ubuntu C++下测试mysql的代码
#include <iostream>
#include <mysql/mysql.h>
using namespace std;
int test_mysql(){
MYSQL mysql;
MYSQL_RES *result;
MYSQL_ROW row;
//initialize MYSQL structure
mysql_init(&mysql);
//connect to database
mysql_real_connect(&mysql,"localhost","root","2699","talk",3306,0,0);
//execute query
mysql_query(&mysql,"select id,name from test");
//get result set
result=mysql_store_result(&mysql);
//process result set
while((row=mysql_fetch_row(result))){
fprintf(stdout,"%s - %s\n",row[0],row[1]);
}
//clean up
mysql_free_result(result);
mysql_close(&mysql);
}
#include <mysql/mysql.h>
using namespace std;
int test_mysql(){
MYSQL mysql;
MYSQL_RES *result;
MYSQL_ROW row;
//initialize MYSQL structure
mysql_init(&mysql);
//connect to database
mysql_real_connect(&mysql,"localhost","root","2699","talk",3306,0,0);
//execute query
mysql_query(&mysql,"select id,name from test");
//get result set
result=mysql_store_result(&mysql);
//process result set
while((row=mysql_fetch_row(result))){
fprintf(stdout,"%s - %s\n",row[0],row[1]);
}
//clean up
mysql_free_result(result);
mysql_close(&mysql);
}
小人本潜水在思源的贴边 ID又多 又有钱 快活乐无边 谁知道站总监 他蛮横不留情面 他勾结站长目无天 占我ID夺我钱 我马甲跟他来翻脸 反被他来把经验减 我同学骂他欺新人 反被他捉进了小黑屋里面 874了一百遍啊一百遍 啊 最后他咬舌自尽 遗恨人间 他还将我和马甲赶出了思源 流落在人间 我为求回思源 无奈行乞在贴前 谁知道站总监他实在太阴险 知道此情形竟派人来暗算将我发文狂删到0篇 小人ID强 残命独留全 可怜马甲他 竟遭删 为求养ID 惟有傍人卖身自作践 一面苦赚钱 一面写诗篇 发誓把名气显 手刃总监意志坚啊 从此总监ID念心间 我永铭记此仇不供戴天 |