向google大神搜 :mysql-connector得http://www.mysql.com/products/connector/這些就是mysql所謂的連接器吧.一路向下看到:C++ Wrapper for MySQL C API (MySQL++) Download http://gna.org/projects/mysqlpp/下載手冊慢慢慢慢看吧你.1. 先到http://tangentsoft.net/mysql++/ 下載mysql++源碼.2. 將mysql++的VS2008的PRO打開后編譯成msyqlpp.lib,mysqlpp.dll等幾個動態或靜態庫。需要注意的是mysql的頭文件及相關庫文件需指定地方或加到VS工具的option->vc directories中.3.請把相應的DEBUG及RELEASE版本的DLL及LIB放到相應的目錄.否則調試報異常.
#include <afxwin.h>
#include <iostream>
#include "lib/mysql++.h"
using namespace std;
int main(){
char name[50];
mysqlpp::Connection conn(false);
if (conn.connect("test","192.168.0.175","root","aaaaaa") ) {
mysqlpp::Query SetCharacterSetQuery = conn.query("SET names 'utf8'");
SetCharacterSetQuery.exec(); //注意這里還要SetCharacterSetQuery.exec() ,和C語言的API不同.
mysqlpp::Query query = conn.query("select * from doc_threads");
mysqlpp::StoreQueryResult res = query.store();
if (res) {
cout << res[0]["id"] << ' ' << CW2A(CA2W(res[0]["name"],CP_UTF8),CP_ACP) << ' ' <<endl;
cout << res[1]["id"] << ' ' << CW2A(CA2W(res[1]["name"],CP_UTF8),CP_ACP) << ' ' <<endl;
}
}
conn.disconnect();
return 0;
}