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


loveline 于 2014-10-16 17:55:38发表:
Thanks for share
sammas1025 于 2014-10-05 16:17:16发表:
谢谢分享
mutou1991 于 2014-09-25 17:24:38发表:
楼主说的好
qxfsy 于 2014-08-09 15:21:06发表:
了解哈!
william2011 于 2014-07-31 12:23:11发表:
谢谢分享
markvenus 于 2014-06-13 11:32:26发表:
我是新手,我要学习
黄绍凯 于 2014-06-09 14:01:30发表:
好啊
执着追求爱 于 2014-06-07 23:39:47发表:
很有用
执着追求爱 于 2014-06-07 23:39:28发表:
不错
senke1 于 2014-01-14 15:06:47发表:
(e:e2s受教了
Jack561 于 2014-01-13 15:20:36发表:
谢谢分享
idlerinwind 于 2013-09-30 11:45:53发表:
努力学习Linux
jyhll123 于 2013-07-25 21:29:43发表:
受教
bnmluo 于 2012-12-14 17:21:33发表:
来学习学习
于 2012-12-12 10:29:59发表:
学习了
于 2012-12-12 10:29:45发表:
学习了,
jdhongtao 于 2012-12-12 09:24:42发表:
多谢,顶起来
醉尘风 于 2012-12-11 14:31:33发表:
学习
gky2009514 于 2012-12-07 12:51:26发表:
新手完成任务,求下书籍~
huangjie540 于 2012-11-28 21:18:32发表:
顶顶顶顶顶顶顶顶顶顶顶:0wpoi2。谢谢楼主额
yiiy88 于 2012-11-28 18:17:50发表:
新人一枚 不会安装任何软件。
ouyangcp 于 2012-10-08 15:04:00发表:
感?您的教?分享!
寂寞弯刀 于 2012-10-05 00:27:19发表:
学习了!
jiangjinta 于 2012-06-24 13:52:31发表:
境界太高,有点像天书:0)1
jiangjinta 于 2012-06-24 13:22:05发表:
感觉想在看天书一样啊(5ty(
努力,加油
liuyanqiu0807 于 2012-06-14 17:12:54发表:
感谢楼主!
fcyyy 于 2012-06-04 12:16:47发表:
qwqqq
Lone_Arena 于 2012-05-09 11:06:47发表:
:0w5ty(1
larmbr 于 2012-05-04 14:56:35发表:
感谢分享,学习了,谢谢!!!
于 2012-04-18 15:45:36发表:
顶啊
tan19880105 于 2012-04-09 11:11:48发表:
我是新手
lunan_gz 于 2012-04-09 10:48:40发表:
顶
toby_lund 于 2012-04-02 22:18:07发表:
楼主辛苦了
fate3008 于 2012-03-30 10:34:08发表:
:0)1
zyzhang12 于 2012-03-07 03:23:52发表:
暂时未用
linuxian 于 2012-03-01 20:06:49发表:
顶楼主
liulanghanzi 于 2012-02-20 16:43:06发表:
楼主说得很仔细
君君兮兮 于 2012-02-17 21:43:54发表:
要是有个视频讲解就完美了。
Lee2012 于 2012-02-11 08:32:36发表:
:0)1
frankhht 于 2012-01-29 20:24:46发表:
顶