#include
#include
#include
#include
void main(int argc, char **argv)
{
MYSQL mysql;
MYSQL_RES *res;
MYSQL_ROW row;
int num,i;
unsigned long *len;
mysql_init(&mysql);
if(!mysql_real_connect(&mysql, "localhost", "root", NULL, "cai",0, 0, 0)) exit(0);;
mysql_query(&mysql, "select * from test");
res = mysql_store_result(&mysql);
if(res==NULL) {
printf("mysql error:%s\n",mysql_error(&mysql));
exit(0);
}
num = mysql_num_fields(res);
while(row=mysql_fetch_row(res)){
len = mysql_fetch_lengths(res);
for(i=0;i printf(" %s :len(%lu) ", row[i], len[i]);
}
printf("\n");
}
mysql_free_result(res);
mysql_close(&mysql);
}
编译命令:
CFG=/export/home/mysql/product/bin/mysql_config
cc -o my my.c `$CFG --cflags` `$CFG --libs`
阅读(594) | 评论(0) | 转发(0) |