Mysql VS 2015呼び出し
テストコードは次のとおりです.
// ConsoleApplication1_mysql_01.cpp : Defines the entry point for the console application.
//
#pragma comment(lib,"libmysql.lib")
#pragma comment(lib, "ws2_32.lib")
#include "stdafx.h"
#include
#include "mysql.h"
#include
#include
#include
#include
void sqlselect(MYSQL *mysql, char *command)
{
int flag = mysql_real_query(mysql, command, strlen(command));
if (flag)
{
printf("Select error:%d, %s
", mysql_errno(mysql), mysql_error(mysql));
return;
}
MYSQL_RES *res = mysql_store_result(mysql); //
MYSQL_FIELD *field = mysql_fetch_fields(res); //
int field_count = mysql_field_count(mysql); //
//
for (int i = 0; i < field_count; i++)
{
printf("%s\t", field[i].name);
}
printf("
");
//
MYSQL_ROW row;
while (row = mysql_fetch_row(res))
{
for (int i = 0; i < field_count; i++)
{
printf("%s\t", row[i]);
}
printf("
");
}
}
int main()
{
// MySQL
MYSQL *mysql = NULL;
mysql = mysql_init((MYSQL *)0);
mysql_real_connect
(
mysql,
"localhost", //
"root", //
"123456", //
"demo", //
0, // ,0 ( 3306)
NULL, // unix_socket NULL, 。 host
0 // 0
);
if (!mysql) //
{
printf("Connection error:%d, %s
", mysql_errno(mysql), mysql_error(mysql));
}
else
{
printf("hello world
");
}
char *command = "select * from student"; //
sqlselect(mysql, command); //
mysql_close(mysql); //
system("pause");
return 0;
return 0;
}
以下の著者に感謝します.http://blog.csdn.net/daso_csdn/article/details/54646859 https://www.2cto.com/database/201701/587128.html