当前位置: 技术问答>linux和unix
用C语言连接MYSQL的问题?在线等.希望大家帮忙.
来源: 互联网 发布时间:2015-05-27
本文导语: #include #include int mysql_query(MYSQL *mysql, const char *query); int main() { MYSQL mysql; int p; mysql_init(&mysql); if (!mysql_real_connect(&mysql, "localhost","", "", "test",0,NULL,0); { fprintf(stderr, "Failed to connect to database: Error: ...
#include
#include
int mysql_query(MYSQL *mysql, const char *query);
int main()
{
MYSQL mysql;
int p;
mysql_init(&mysql);
if (!mysql_real_connect(&mysql, "localhost","", "", "test",0,NULL,0);
{
fprintf(stderr, "Failed to connect to database: Error: %sn",
mysql_error(&mysql));
}
char *string="insert into mytest set name='XP',QQ='29595350'";
p=mysql_query(MYSQL *mysql, string);
printf("%d/n",p);
return 0;
}
上面代码在VC下面编译时通不过,怎么办?怎么解决这个问题呢?
错误是:"Cannot open include file: 'mysql.h': No such file or directory"
#include
int mysql_query(MYSQL *mysql, const char *query);
int main()
{
MYSQL mysql;
int p;
mysql_init(&mysql);
if (!mysql_real_connect(&mysql, "localhost","", "", "test",0,NULL,0);
{
fprintf(stderr, "Failed to connect to database: Error: %sn",
mysql_error(&mysql));
}
char *string="insert into mytest set name='XP',QQ='29595350'";
p=mysql_query(MYSQL *mysql, string);
printf("%d/n",p);
return 0;
}
上面代码在VC下面编译时通不过,怎么办?怎么解决这个问题呢?
错误是:"Cannot open include file: 'mysql.h': No such file or directory"
|
-I /usr/local/include
其中 /usr/local/include 根据实际情况而定
其中 /usr/local/include 根据实际情况而定
|
vc 里面有个编译菜单 里面有编译连接选项 加上你的mysql.h所在路径
和mysqlclient 路径
和mysqlclient 路径
|
你使用VC编译的吗????
在项目设置中找到include项加入就行了
在项目设置中找到include项加入就行了
|
找倒你机器上mysql.h的目录
#include "mysql.h的目录mysql.h"
#include "mysql.h的目录mysql.h"