if( mysql_init(&mysql) == NULL ) { fprintf(stderr,"Init mysql err!"); return -1; } if (mysql_real_connect(&mysql,host,user,passwd,db,0,NULL,0) == NULL) { fprintf(stderr,"Connect to mysql Error:%s!",mysql_error(&mysql)); return -1; } else { puts("Connect to mysql success!"); }
doQuery(); mysql_close(&mysql); return 0; }
但是我用命令 gcc -o test test.c 编译时有如下错误: test.c:4:25: error: mysql/mysql.h: No such file or directory test.c:7: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'mysql' test.c: In function 'doQuery': test.c:11: error: 'MYSQL_ROW' undeclared (first use in this function) test.c:11: error: (Each undeclared identifier is reported only once test.c:11: error: for each function it appears in.) test.c:11: error: expected ';' before 'm_row' test.c:12: error: 'MYSQL_RES' undeclared (first use in this function) test.c:12: error: 'm_res' undeclared (first use in this function) test.c:16: error: 'mysql' undeclared (first use in this function) test.c:25: error: 'm_row' undeclared (first use in this function) test.c: In function 'main': test.c:39: error: 'mysql' undeclared (first use in this function) test.c:39: warning: comparison between pointer and integer test.c:44: warning: comparison between pointer and integer test.c:57:2: warning: no newline at end of file