#include <stdlib.h>
#include <stdio.h>
#include <WinSock.h>
#include <Windows.h>
#include <mysql.h>
#pragma comment(lib, "libmysql.lib")
MYSQL mysql;
int find_ps()
{
// MYSQL_ROW m_row;
MYSQL_RES *m_res;
char sql[1024];
int res=1;
// int *id;
printf(sql,"select * from abing");
if(mysql_query(&mysql,sql)!=0)
{
return res;
}
m_res = mysql_store_result(&mysql);
if(m_res==NULL)
{
res = 3;
return res;
}
return res;
}
int db_close()
{
mysql_close(&mysql);
return 0;
}
//你需要设置链接库!!!
int main(){
char host[32]="localhost"; // mysql host
char user[32]="root";//mysql user name
char passwd[32]=""; //mysql pwd
char dbname[32]="test";//mysql db
int d;
if( mysql_init(&mysql) == NULL )
return 1;
if (mysql_real_connect(&mysql,host,user,passwd,dbname,0,NULL,0) == NULL)
{
return 1;
}
else
{
printf("connected to the db!\n");
d = find_ps();
printf("the num is: %d\n",d);
db_close();
return 0;
}
}