1.软件环境ubuntu10.10
2. 安装mysql -- sudo apt-get install mysqlserver
3. 安装 libmysqlclient15-dev -- sudo apt-get install libmysqlclient15-dev
(如果提示没有安装包,可以用sudo apt-get install update和sudo apt-get install upgrade进行更新和升级,如果没有网络看来很难学习ubuntu)
4 下载mysql++ --
http://tangentsoft.net/mysql++/releases/mysql++-3.0.9.tar.gz
5 tar -vxf mysql++-3.0.9.tar.gz
6 cd mysql++-3.0.9
7. ./configure --prefix=/usr
8. make 第一次可能失败,会提示:./lib/refcounted.h:258:2: 错误: ‘size_t’不是一个类型名
./lib/refcounted.h: 在构造函数‘mysqlpp::RefCountedPointer
解决方法:打开./lib/refcounted.h,添加#include
9.重新编译make
10. sudo make install
11. 安装完毕。
12 测试 代码
#include
#include
#include
using namespace std;
int main(int argc, char *argv[])
{
// Get database access parameters from command line
const char* db = 0, *server = 0, *user = 0, *pass = "";
db = "school";
server = "127.0.0.1";
user = "root";
pass = "hlf";
// Connect to the sample database.
mysqlpp::Connection conn(false);
if (conn.connect(db, server, user, pass)) {
// Retrieve a subset of the sample stock table set up by resetdb
// and display it.
mysqlpp::Query query = conn.query("select * from student");
if (mysqlpp::StoreQueryResult res = query.store()) {
cout << "We have:" << endl;
mysqlpp::StoreQueryResult::const_iterator it;
for (it = res.begin(); it != res.end(); ++it) {
mysqlpp::Row row = *it;
cout << '\t' << row[0] << endl;
}
}
else {
cerr << "Failed to get item list: " << query.error() << endl;
return 1;
}
return 0;
}
else {
cerr << "DB connection failed: " << conn.error() << endl;
return 1;
}
}
13 makefile
tsql:tsql.cpp
g++ -o tsql tsql.cpp -I/usr/include/mysql -I/usr/include/mysql++ -L/usr/lib -lmysqlpp
注意,一定要有lmysqlpp,该句是为了使用库libmysqlpp.a
kaka_425644 于 2012-01-20 10:53:58发表:
顶
Askanswer 于 2012-01-19 19:42:10发表:
支持一个。
迷你版vcxz 于 2012-01-18 15:33:03发表:
顶顶顶顶顶顶顶顶顶顶顶顶顶
Growth兆 于 2012-01-18 10:03:41发表:
感谢haolifengwang的分享,本贴加入到论坛顶置的Linux应用贴中
onquer 于 2012-01-17 10:24:00发表:
支持