#include <iostream>
#include <string.h>
#include "winsock.h"
#include <mysql.h>
#pragma comment(lib,"ws2_32.lib")
#pragma comment(lib,"libmysql.lib")
using namespace std;
int main()
{
char* host="192.168.1.21";
char* user="root";
char* pwd="111";
char* dbname="WGPBX";
char* sql="select * from T_INTERPHONE_PORT";
MYSQL *mysql;
mysql=mysql_init(NULL);
if(!(mysql=mysql_real_connect(mysql,host,user,pwd,dbname,0,NULL,0)))
{
cout<<"失败";
return 1;
}
cout<<"连接数据库成功";
MYSQL_RES *query=NULL;
MYSQL_ROW row;
if(mysql_query(mysql,sql))
{
cout<<mysql_error(mysql);
return 0;
}
if(!(query=mysql_store_result(mysql)))
{
cout<<mysql_error(mysql);
return 0;
}
// cout<<"nums:"<<mysql_num_fields(query)<<endl;
cout<<"###"<<endl;
while(row=mysql_fetch_row(query))
{
/*
for(int i=0;i<12;i++)
{
cout<<i;
if(row[i]!=NULL)
{
cout<<row[i]<<"-";
}
else
cout<<"NULL"<<"-";
}*/
cout<<row[5]<<endl;
}
return 0;
}