一段连接mysql的c代码,编译一直不能通过,苦闷中,求助~
#include
#include
#include
#include "/usr/local/mysql/include/mysql.h"
int main(int argc, char *argv[]) {
MYSQL my_connection;
MYSQL_RES *res_ptr; /*指向检索的结果存放地址的指针*/
MYSQL_ROW sqlrow; /*返回的记录信息*/
MYSQL_FIELD *fd; /*字段结构指针*/
char aszflds[25][25]; /*用来存放各字段名*/
// char szTargetDSN[]=db; /*用来存放数据库的名字*/
int res; /*执行查询操作后的返回标志*/
int i,j,k;
mysql_init(&my_connection);
/*mysql_real_connect(&mysql,host,user,passwd,dbname,0,NULL,0) == NULL)*/
if (mysql_real_connect(&my_connection, "root", "root", "123456","authority",0,NULL,CLIENT_FOUND_ROWS))
{
printf("Connection success\n");
res = mysql_query(&my_connection, "select result from authority where id=uid");
if (res)
{
printf("SELECT error:%s\n",mysql_error(&my_connection));
}
else
{
res_ptr=mysql_store_result(&my_connection);
if(res_ptr)
{
printf("Retrieved %lu Rows\n",(unsigned long)mysql_num_rows(res_ptr));
/*取得各字段名*/
for(i=0;fd=mysql_fetch_field(res_ptr);i++)
strcpy(aszflds,fd->name);
/*输出各条记录*/
printf("下面是检索出的各条记录信息:\n");
j=mysql_num_fields(res_ptr);
for(i=0;i
printf("%s\t",aszflds);
printf("\n");
while((sqlrow=mysql_fetch_row(res_ptr)))
{
for(i=0;i
printf("%s\t",sqlrow);
printf("\n");
}
if (mysql_errno(&my_connection))
{
fprintf(stderr,"Retrive error:s\n",mysql_error(&my_connection));
}
}
mysql_free_result(res_ptr);
}
mysql_close(&my_connection);
}
else
{
fprintf(stderr, "Connection failed\n");
if (mysql_errno(&my_connection))
{
fprintf(stderr, "Connection error %d: %s\n",
mysql_errno(&my_connection),
mysql_error(&my_connection));
}
}
return EXIT_SUCCESS;
}
gcc -o query query.c -L /usr/local/mysql/lib/*.a -lz 之后就报如下错误:
lib/libmysqlclient.a (password.o) (.text+0x308): In function 'scramble_323':
undefined reference to 'floor'.
[ 本帖最后由 houhou_mao 于 2008-5-29 14:11 编辑 ]
--------------------next---------------------
阅读(596) | 评论(0) | 转发(0) |