- 论坛徽章:
- 0
|
本帖最后由 canigreen 于 2011-11-30 15:11 编辑
编译参数为:gcc -o my mysql.c -I /usr/local/mysql/include/mysql/ -L /usr/local/mysql/lib/mysql/ -lmysqlclient
编译的时候会出现错误,确认过,指针类型是一样的,但不知道为什么会出现错误,C语言代码在后面:
- [root@XXXX work]# gcc -o my mysql.c -I /usr/local/mysql/include/mysql/ -L /usr/local/mysql/lib/mysql/ -lmysqlclient
- mysql.c: In function ‘main’:
- mysql.c:40: warning: assignment from incompatible pointer type
复制代码 执行输入会出来非常多的其它信息,不知道怎么回事,还希望在行的人能指点一二,感激不尽:
执行程序后输出结果如下,除了前三段记录是要的,其它的都是多出来的,不知道是从哪儿来的,C语言代码在后面:- Connected...
- mysql_num_fields is 5
- 2 1 feeds 5d8745cd7e10fa00731a1bed9759ab1afed18437 2011-11-22 00:08:56 oXic</ord
- 4 3 feeds ea5f71be6fdc143c790f72248799da5f1a22e0d7 2011-11-22 00:16:29 o
- 6 4 feeds a6a2400c7efb15111352c1912eb3f43caadf56b5 2011-11-25 19:12:56 tion>
- <collation name="geostd8_general_ci" id="92" order="Georgian" flag="primary"/>
- <collation name="geostd8_bin" id="93" order="Binary" flag="binary"/>
- </charset>
- <charset name="binary">
- <description>Binary pseudo charset</description>
- <collation name="binary" id="63" order="Binary">
- <flag>primary</flag>
- <flag>compiled</flag>
- </collation>
- </charset>
- <charset name="cp932">
- <family>Japanese</family>
- <description>SJIS for Windows Japanese</description>
- <alias>ms_cp932</alias>
- <alias>sjis_cp932</alias>
- <alias>sjis_ms</alias>
- <collation name="cp932_japanese_ci" id="95" order="Japanese">
- <flag>primary</flag>
- <flag>compiled</flag>
- </collation>
- <collation name="cp932_bin" id="96" order="Binary">
- <flag>binary</flag>
- <flag>compiled</flag>
- </collation>
- </charset>
- <charset name="eucjpms">
- <family>Japanese</family>
- <description>UJIS for Windows Japanese</description>
- <alias>eucjpms</alias>
- <alias>eucJP_ms</alias>
- <alias>ujis_ms</alias>
- <alias>ujis_cp932</alias>
- <collation name="eucjpms_japanese_ci" id="97" order="Japanese">
- <flag>primary</flag>
- <flag>compiled</flag>
- </collation>
- <collation name="eucjpms_bin" id="98" order="Japanese">
- <flag>binary</flag>
- <flag>compiled</flag>
- </collation>
- </charset>
- </charsets>
- The number of no is :18
- 代码如下:
复制代码- #include "stdio.h"
- #include "stdlib.h"
- #include "mysql.h"
- #include "string.h"
- int main()
- {
- MYSQL mysql;
- MYSQL_RES *res;
- MYSQL_ROW *row;
- /* MYSQL_FIELD *field; */
- int j;
- int no;
- char *query;
- int r,t;
- /* Connect to mysql */
- mysql_init(&mysql);
- if(!mysql_real_connect(&mysql,"localhost","root","1352456","redminedb",0,NULL,0))
- {
- printf("Error connecting to databases:\n%si\n",mysql_error(&mysql));
- return 1;
- }
- else
- printf("Connected...\n");
- query="select * from tokens";
- t=mysql_real_query(&mysql,query,(unsigned int)strlen(query));
- if(t)
- {
- printf("Error making query:%s\n",mysql_error(&mysql));
- return 1;
- }
- res=mysql_store_result(&mysql);
- j=mysql_num_fields(res);
- no=0;
- printf("mysql_num_fields is %d\n",j);
- while(row=mysql_fetch_row(res))
- {
- for(t=0;t<=j;t++)
- {
- printf("%s\t",row[t]);
- no++;
- }
- printf("\n");
- }
- printf("The number of no is :%d\n",no);
- mysql_close(&mysql);
- return 0;
- }
复制代码 |
|