linux下配置mysql++

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::RefCountedPointer()’中:

解决方法:打开./lib/refcounted.h,添加#include 和using namespace std;

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值