#include <windows.h>
#include <iostream>
#include <mysql.h>
#include <stdio.h>
using namespace std;
int main()
{
//connection params
FILE *file;
char *host = "localhost";
char *user = "root";
char *pass = "123456";
char *db = "mysql";
//sock
MYSQL *sock;
MYSQL_RES *results;
MYSQL_ROW record;
sock = mysql_init(0);
if (sock)
cout << "sock handle ok!" << endl;
else
{
cout << "sock handle failed!" << mysql_error(sock)<< endl;
}
//connection
if (mysql_real_connect(sock, host, user, pass, db, 3306, NULL, 0))
cout << "connection ok!" << endl;
else {
cout << "connection fail: " << mysql_error(sock)<< endl;
}
//connection character set
mysql_set_character_set(sock,"gb2312");
cout << "connection character set: " << mysql_character_set_name(sock) << endl;
//wait for posibility to check system/mysql sockets
if(mysql_query(sock,"select * from user"))
{
cout <<"very good!" <<endl;
}
//links=mysql_fetch_row(sock);
results=mysql_store_result(sock);
printf("user\tlevel\n");
while(record=mysql_fetch_row(results))
{
printf("%s\t %s\n",record[1],record[3]);
}
mysql_free_result(results);
system("PAUSE");
//closing connection
mysql_close(sock);
return EXIT_SUCCESS;
}