代碼
#include <cstdlib>
#include <string>
#include
using namespace std;
string host=
string user=
string pwd=
string dbname=
string sql=
unsigned int port=
int status;
int main(){
MYSQL *mysql;
mysql=mysql_init(
MYSQL_RES *result;
MYSQL_ROW row;
if(mysql_real_connect(mysql
cout <<
return EXIT_FAILURE;
}else{
cout <<
}
mysql_set_character_set(mysql
status=mysql_query(mysql
if(status !=
cout <<
}
cout <<
result=mysql_store_result(mysql);
while(row=mysql_fetch_row(result)){
cout << row[
}
mysql_free_result(result);
mysql_close(mysql);
}
編譯
g++
後面的那些用來指定mysql安裝的時候包含路徑和庫文件路徑
From:http://tw.wingwit.com/Article/program/MySQL/201311/29472.html