mysql:mysql++的安装与使⽤
测试版本mysql++-3.0.
mysql下载后的初次使用//hello.cpp
#include <iostream>
#include <mysql++.h>
using namespace std;
int main()
{
cout<<"hello"<<endl;
getchar();
return 0;
}
编译(注意格式和包含的内容):
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++ - 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
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
类似iconvpp对iconv的封装,MySQL++同样是采⽤C++对MySQL 原有C接⼝的封装。当希望通过C++语⾔实现访问MySQL数据库时,MySQL++是⼀个⾮常好的选择。
./configure -> make -> make install
[cpp]
#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 (t(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" << () << 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

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。