1个回答
2013-08-03
展开全部
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <mysql/mysql.h>
int main(){
MYSQL *mysql;
MYSQL_RES *res;
MYSQL_ROW row;
char query[1024];
int t,r;
mysql=mysql_init(NULL);
if (!mysql_real_connect(mysql,"test","root",
"123","test",0,NULL,0))
{
printf( "Error connecting to database: %s\n",mysql_error(mysql));
}
else printf("Connected...\n");
sprintf(query,"select count(*) from first");
t=mysql_query(mysql,query);
if (t)
{
printf("Error making query: %s\n",
mysql_error(mysql));
}
else printf("Query made...\n");
res=mysql_use_result(mysql);
for(r=0;r<mysql_field_count(mysql);r++){
row=mysql_fetch_row(res);
if(row<0) break;
for(t=0;t<mysql_num_fields(res);t++)
printf("%s",row[t]);
printf("\n");
}
mysql_close(mysql);
return 0;
}
#include <stdlib.h>
#include <string.h>
#include <mysql/mysql.h>
int main(){
MYSQL *mysql;
MYSQL_RES *res;
MYSQL_ROW row;
char query[1024];
int t,r;
mysql=mysql_init(NULL);
if (!mysql_real_connect(mysql,"test","root",
"123","test",0,NULL,0))
{
printf( "Error connecting to database: %s\n",mysql_error(mysql));
}
else printf("Connected...\n");
sprintf(query,"select count(*) from first");
t=mysql_query(mysql,query);
if (t)
{
printf("Error making query: %s\n",
mysql_error(mysql));
}
else printf("Query made...\n");
res=mysql_use_result(mysql);
for(r=0;r<mysql_field_count(mysql);r++){
row=mysql_fetch_row(res);
if(row<0) break;
for(t=0;t<mysql_num_fields(res);t++)
printf("%s",row[t]);
printf("\n");
}
mysql_close(mysql);
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询