c mysql执行SQL出错_mysql c接口程序 执行sql语句出错,帮看看

1#include"/usr/include/mysql/mysql.h"2#include3#include45intmain(){6MYSQLmysql,*ptr;7MYSQL_ROWrow;8mysql_init(&mysql);9if((ptr=mysql_real_connect(&mysq...

1 #include "/usr/include/mysql/mysql.h"

2 #include

3 #include

4

5 int main(){

6 MYSQL mysql,*ptr;

7 MYSQL_ROW row;

8 mysql_init(&mysql);

9 if((ptr=mysql_real_connect(&mysql,"localhost","root","787898","psx",0,NULL,0))!=0)

10 printf("connected..\n");

11 else{

12 printf("Error connecting to database: %s\n" ,mysql_error(&mysql));

13 exit(1);

14 }

15

16 if(!mysql_query(ptr,"source /home/longuohong/create.sql;")){

17 }

18 printf("ok\n");

19 }

20 else printf("%s\n",mysql_error(ptr));

21 mysql_close(ptr);

22 return 0;

23 }

~

在msyql下直接执行source /home/longuohong/create.sql;没错,可是运行该程序执行这条语句却出现了语法错误。困惑中。。。

if(!mysql_query(ptr,"source /home/longuohong/create.sql;")){

后面那个括号是没有的,不小心加上去的,程序本身没语法错误

在线等达人指教。。。。。。。。

longuohong@longuohong-desktop:~$ gcc -o connect connect.c -lmysqlclient

longuohong@longuohong-desktop:~$ ./connect

connected..

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'source /home/longuohong/create.sql' at line 1

在mysql执行:

mysql> source /home/longuohong/create.sql;

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

展开

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值