-
MySQL 5.7.24版本的DLL库文件
资源介绍
mysql库文件和头文件,可以用VC调用库函数
#include "stdafx.h"
#include "mysql.h"
#include
#include < list >
#pragma comment(lib,"libmysql.lib")
using namespace std;
int main()
{
char strSQL[256] = { 0 };
MYSQL mysql;
mysql_init(&mysql;);
char* host = "localhost";
char* user = "root";
char* pwd = "";
char* dbname = "test";
int port = 3306;
if (!mysql_real_connect(&mysql;, host, user, pwd, dbname, port, NULL, 0))
{
printf("%s\n", mysql_error(&mysql;));
printf("connect failed\n");
return 1;
}
// query
char* tbname = "student";
sprintf(strSQL, "select * from %s", tbname);
if (mysql_real_query(&mysql;, strSQL, strlen(strSQL)))
{
printf("%s\n", mysql_error(&mysql;));
printf("read failed!\n");
mysql_close(&mysql;);
return 2;
}
//get result
MYSQL_RES* result;
if (!(result = mysql_use_result(&mysql;)))
{
printf("%s\n", mysql_error(&mysql;));
printf("read result failed!\n");
mysql_close(&mysql;);
return 3;
}
//show data
MYSQL_ROW row;
int num = mysql_num_fields(result);// field number
while (row = mysql_fetch_row(result))
{
for (int i = 0; i < num; ++i)
printf("%s\t", row[i]);
printf("\n");
}
mysql_free_result(result);
mysql_close(&mysql;);
system("Pause");
return 0;
}
- 上一篇: C#连接MySQL数据库
- 下一篇: C#连接MySql的最新Dll