原:http://hi.baidu.com/ismayday/blog/item/9e4ec75c63491f45fbf2c0b8.html
测试版本mysql++-3.0.9.tar.gz
mysql++官方例子:http://tangentsoft.net/mysql++/doc/html/userman/tutorial.html#examples
安装mysql++. 以root用户安装:
./configure --prefix=/usr/local --enable-thread-check
make
make install
修改/etc/ld.so.conf文件,添加/usr/local/lib
/sbin/ldconfig
/bin/ln -s /usr/local/lib/libmysqlpp.so /usr/lib/libmysqlpp.so
测试:
![](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/2f88ce130b654eb5dc6788e02dbcfc90.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/df37983f39daa189b8c814e01a6a9011.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/df37983f39daa189b8c814e01a6a9011.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/df37983f39daa189b8c814e01a6a9011.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/0ac3a2d53663ec01c7f7225264eeefae.gif)
编译(注意格式和包含的内容):
g++ -Wno-deprecated -L/usr/lib/mysql -lmysqlclient -L/usr/local/lib -lmysqlpp -Ilib -I/usr/include/mysql -I/usr/local/include/mysql++ -o testhello.cpp -lpthread
如果能够编译成功,且不出现运行错误。
则下一步可进行数据库的各种操作了。
安装错误 1:找不到库,需调整顺序。
g++ -o ssqlsxlat.exe ssqlsxlat_genv2.o ssqlsxlat_main.o -L.-lmysqlclient -L/usr/local/mysql/lib -Wl,--enable-auto-import-lmysqlpp_ssqls2parse -lmysqlpp -lintl
或
出错提示:/mysql++-3.1.0/./ssx/parsev2.cpp:579: undefined reference to `mysqlpp::internal::str_to_lwr(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)'
此刻手动键入如下命令:
g++ -o test_ssqls2 test_ssqls2_ssqls2.o -lmysqlpp_ssqls2parse -WI,--as-needed -L. -L/usr/local/lib/mysql -lmysqlclient -lmysqlpp
然后继续安装,sudo make install
原:http://hi.baidu.com/haolifengwang/item/f286be63254ddf91c4d2494d
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1.mysql++介绍
类似iconvpp对iconv的封装,MySQL++同样是采用C++对MySQL 原有C接口的封装。当希望通过C++语言实现访问MySQL数据库时,MySQL++是一个非常好的选择。
2.mysql++下载
mysql的官网是http://tangentsoft.net/mysql++/, 下载最新稳定版mysql++-3.1.0.tar.gz
3.mysql++安装
./configure -> make -> make install
4.mysql++基本使用
#include "mysql++.h"
using namespace mysqlpp;
using namespace std;
int main()
{
//构造一个Connection类的对象
Connection con(false);
const char* db = "wwt_mainsitedb", *server = "192.168.1.150", *user = "root", *pass = "111";
if (con.connect(db, server, user, pass))
{
cout << "success" << endl;
string sql = "select * from wwt_users";
Query query = con.query(sql);
if (StoreQueryResult rs = query.store())
{
StoreQueryResult::const_iterator it;
for (it = rs.begin(); it != rs.end(); ++it)
{
Row row = *it;
cout << "/t" << row[0] << "/t" << row[1] << endl;
}
}
else
{
cerr << "Failed to get item list: " << endl;
return -1;
}
}
else
{
cout << "Failed to connect DB" << con.error() << endl;
return -1;
}
return 0;
}
编译:g++ -o test test.cpp -I/usr/include/mysql -I/usr/include/mysql++/ -I/usr/local/include/mysql++/ -lmysqlpp -lmysqlclient
运行: ./test