#include <iostream>
#include <my_global.h>
#include <mysql.h>
//#include<windows.h>
#include<winsock2.h>
#pragma comment(lib,"libmysql.lib");
int main(void) {
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
/* db configure*/
char *server = "192.168.0.175";
char *user = "root";
char *password = "aaaaaa";
char *database = "demo";
int port=3306;
conn = mysql_init(NULL);
/* Connect to database */
if (!mysql_real_connect(conn, server, user, password, database, port, NULL, 0)) {
printf("%s\n", mysql_error(conn));
exit(0);
}
/* send SQL query */
//mysql_query(conn, "set names gbk");
if (mysql_query(conn, "select * from doc_threads")) {
printf("%s\n", mysql_error(conn));
exit(0);
}
res = mysql_use_result(conn);
/* output table name */
printf("MySQL Tables in mysql database:\n");
while ((row = mysql_fetch_row(res)) != NULL)
printf("%s - %s - %s\n", row[0],row[1],row[2]);
/* close connection */
mysql_free_result(res);
mysql_close(conn);
return 0;
}
个人感觉,简单的应用,还是C风格的MySQL操作简单点.