mysql++的安装和基本用法

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

你可能感兴趣的:(mysql++的安装和基本用法)