1个回答
展开全部
if(!mysql_real_connect(&mysql,"localhost","root","zhouqiang","db_books",0,NULL,0))
{
printf("到这了");
printf("\n\t Can not connect db_books!\n");
}
else
{
if(mysql_query(&mysql,"select * from tb_book"))
{
printf("\n\t Query tb_book failed!\n");
}
else
{
result = mysql_store_result(&mysql);
if(mysql_num_rows(result)!=0)
{
printf("\t————————————————————————\n");
printf("\t Show All The Books \n");
printf("\t————————————————————————\n");
printf("\t ID BookName Author BookConcern \n");
printf("\t————————————————\n");
while((row=mysql_fetch_row(result)))
{
fprintf(stdout,"\t %s %s %s %s\n",row[0],row[1],row[2],row[3]);
}
printf("\t————————————————————————\n");
}
else
printf("\n\t No record!\n");
mysql_free_result(result);
}
mysql_close(&mysql);
}
}
{
printf("到这了");
printf("\n\t Can not connect db_books!\n");
}
else
{
if(mysql_query(&mysql,"select * from tb_book"))
{
printf("\n\t Query tb_book failed!\n");
}
else
{
result = mysql_store_result(&mysql);
if(mysql_num_rows(result)!=0)
{
printf("\t————————————————————————\n");
printf("\t Show All The Books \n");
printf("\t————————————————————————\n");
printf("\t ID BookName Author BookConcern \n");
printf("\t————————————————\n");
while((row=mysql_fetch_row(result)))
{
fprintf(stdout,"\t %s %s %s %s\n",row[0],row[1],row[2],row[3]);
}
printf("\t————————————————————————\n");
}
else
printf("\n\t No record!\n");
mysql_free_result(result);
}
mysql_close(&mysql);
}
}
追问
大哥 你这么写也不知道调用的头文件是哪里的啊
追答
#include
#include
#include
#include
#pragma comment(lib,"libmysql.lib")
MYSQL mysql;
MYSQL_RES *result;
MYSQL_ROW row;
char ch[2];
void ShowAll(void)
{
if(!mysql_real_connect(&mysql,"localhost","root","root","db_books",0,NULL,0))
{
printf("\n\t Can not connect db_books!\n");
}
else
{
if(mysql_query(&mysql,"select * from tb_book"))
{
printf("\n\t Query tb_book failed!\n");
}
else
{
result = mysql_store_result(&mysql);
if(mysql_num_rows(result)!=0)
{
printf("\t————————————————————————\n");
printf("\t Show All The Books \n");
printf("\t————————————————————————\n");
printf("\t ID BookName Author BookConcern \n");
printf("\t————————————————\n");
while((row=mysql_fetch_row(result)))
{
fprintf(stdout,"\t %s %s %s %s\n",row[0],row[1],row[2],row[3]);
}
printf("\t————————————————————————\n");
}
else
printf("\n\t No record!\n");
mysql_free_result(result);
}
mysql_close(&mysql);
}
}
void main(void)
{
int exit = 1;
int sele;
mysql_init(&mysql);
while(exit)
{
showmenu();
printf("请输入你的选择:\n");
scanf("%d", &sele);
switch(sele)
{
case 1:
ShowAll();
break;
case 2:
AddBook();
break;
case 3:
ModifyBook();
break;
case 4:
DeleteBook();
break;
case 5:
QueryBook();
break;
case 6:
exit = 0;
printf("谢谢使用!再见。。");
break;
default:
break;
}
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询