【mysql5.6】连接vs2010
时间:2021-07-01 10:21:17
帮助过:3人阅读
"winsock.h"
#include "mysql.h"
using namespace std;
int main()
{
MYSQL *
mysql;
mysql =
mysql_init(NULL);
char * sql =
"select * from emp";
MYSQL_RES *
result;
MYSQL_ROW row;
int r, num;
if(mysql_real_connect(mysql,
"localhost",
"root",NULL,
"test1",
3306,NULL,
0))
{
mysql_set_character_set(mysql,"gbk");
if(!
mysql_query(mysql, sql))
{
result =
mysql_store_result(mysql);
if(result ==
NULL)
return 0;
num =
mysql_num_fields(result);
unsigned long * lengths =
mysql_fetch_lengths(result);
while(row =
mysql_fetch_row(result))
{
for(r =
0; r < num; ++
r)
{
cout<<row[r]<<
‘ ‘;
}
cout<<
endl;
}
mysql_free_result(result);
}
mysql_close(mysql);
}
return 0;
}
函数在mysql中文参考手册的API部分有讲:http://www.cbi.pku.edu.cn/chinese/documents/csdoc/mysql/manual_Clients.html#C
【mysql5.6】连接vs2010
标签: