用c++连接mysql5时遇到的问题
如何解决以下问题,谢谢这程序从网上搜的,相应的参数该过了,编译时报错如下
1>------ 已启动生成: 项目: connection2, 配置: Debug Win32 ------
1>正在编译...
1>maim.cpp
1>c:\mysql\mysql server 5.0\include\mysql_com.h(183) : error C2146: 语法错误 : 缺少“;”(在标识符“fd”的前面)
1>c:\mysql\mysql server 5.0\include\mysql_com.h(183) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>c:\mysql\mysql server 5.0\include\mysql_com.h(183) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>c:\mysql\mysql server 5.0\include\mysql_com.h(358) : error C2065: “SOCKET”: 未声明的标识符
1>c:\mysql\mysql server 5.0\include\mysql_com.h(358) : error C2146: 语法错误 : 缺少“)”(在标识符“s”的前面)
1>c:\mysql\mysql server 5.0\include\mysql_com.h(359) : error C2059: 语法错误 : “)”
1>e:\workspace\connection2\connection2\maim.cpp(26) : warning C4244: “=”: 从“my_ulonglong”转换到“unsigned long”,可能丢失数据
1>生成日志保存在“file://e:\workspace\connection2\connection2\Debug\BuildLog.htm”
1>connection2 - 6 个错误,1 个警告
代码如下
#include "C:\MySQL\MySQL Server 5.0\include\mysql.h" /*为绝对路径*/
#include <stdio.h>
int main(int argc,char *argv[])
{
char *user = "root", *pwd = "", *dbname = "tvshow";
MYSQL mysql;
MYSQL_RES *mysql_ret;
MYSQL_ROW mysql_row;
unsigned long num_rows;
int ret;
mysql_init(&mysql);
if(mysql_real_connect(&mysql,NULL,user,pwd,dbname,0,NULL,0))
{
printf("Connection success!\n");
ret = mysql_query(&mysql,"SELECT * FROM t_type_word");
if(!ret)
{
printf("Query Success!\n");
mysql_ret = mysql_store_result(&mysql);
if(mysql_ret != NULL)
{
printf("Store Result Success!\n");
num_rows = mysql_num_rows(mysql_ret);
if(num_rows != 0)
{
printf("%d\n",num_rows);
while(mysql_row = mysql_fetch_row(mysql_ret))
{
printf("%s\t%s\t%s\t%s\t%s\t%s\n",mysql_row[0],mysql_row[1],mysql_row[2],mysql_row[3],mysql_row[4],mysql_row[5]);
}
}
else
{
printf("mysql_num_rows Failed!\n");
return -1;
}
mysql_free_result(mysql_ret);
return 0;
}
else
{
printf("Store Result Failed!\n");
return -1;
}
}
else
{
printf("Query Failed!\n");
return -1;
}
}
else
{
printf("Connection Failed\n");
return -1;
}
}