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)
展开