今天简要学习一下mysql++或者又叫mysqlpp。环境:windows xp, 编译工具:VS2008.
哦,把今天的时间标上去吧:2012-04-27, 打开网站:http://tangentsoft.net/mysql++/ 我下载了mysql++-3.1.0.tar.gz,解压到自己的硬盘下面找到。
因为我是用的VS2008,所以打开解压目录下的VC2008的mysql++.sln,编译完之后在Debug目录下生成了:mysqlpp_excommon.lib/mysqlpp_d.dll/mysqlpp_d.lib。
当然动态库和静态库随便用一个就行,将上面生成的库拷贝到自己工程可以找到的目录下面就可以编译自己的项目了。
至于说mysqlpp_d.dll/mysqlpp_d.lib后面的"_d"应该是Debug的意思。
好像没有遇到其他什么问题吧!
就这些了,贴一个压缩包中稍微改动之后的例子吧!


1 #include <mysql++.h> 2 3 #include <iostream> 4 #include <iomanip> 5 using namespace std; 6 7 int main(int argc, char *argv[]){ 8 // Connect to the sample database. 9 mysqlpp::Connection conn(false); 10 if (conn.connect(mysqlpp::examples::db_name, "localhost","root", "123456")) { 11 mysqlpp::Query query = conn.query("select * from mytest"); 12 if (mysqlpp::StoreQueryResult res = query.store()) { 13 cout << "We have:" << endl; 14 mysqlpp::StoreQueryResult::const_iterator it; 15 for (it = res.begin(); it != res.end(); ++it) { 16 mysqlpp::Row row = *it; 17 cout << '\t' << row[1] << endl; 18 } 19 } 20 else { 21 cerr << "Failed to get item list: " << query.error() << endl; 22 return 1; 23 } 24 } 25 else { 26 cerr << "DB connection failed: " << conn.error() << endl; 27 return 1; 28 } 29 system("pause"); 30 return 0; 31 }
不做过多注释,详细请查看专业文档!