#1.简介

MySQL++ is a powerful C++ wrapper for MySQL’s C API. Its purpose is to make working with queries as easy as working with STL containers.

 

#2.编译安装

下载MySQL++安装包 http://www.tangentsoft.net/mysql++/releases/mysql++-3.2.2.tar.gz

##2.1.ubuntu

###安装libmysqlclient
sudo apt-get install libmysqlclient-dev

locate libmysqlclient 从结果中可用看到libmysqlclient.so在/usr/lib/x86_64-linux-gnu/目录下

头文件:/usr/include/mysql

lib: /usr/lib/x86_64-linux-gnu

###编译
sudo ./configure --with-mysql-lib=/usr/lib/x86_64-linux-gnu
sudo make
sudo make install

/usr/local/include/mysql++
/usr/local/lib/mysqlpp.so

头文件:/usr/local/include/mysql++

lib: /usr/local/lib

###so的配置
/etc/ld.so.conf /usr/local/lib

 

##2.2.centos

###安装libmysqlclient
yum install mysql-devel
rpm -ql mysql-devel 从结果中可以看到libmysqlclient.so在/usr/lib64/mysql/目录下

头文件:/usr/include/mysql

lib:/usr/lib64/mysql/

###编译
./configure --prefix=/usr/local --enable-thread-check --with-mysql-lib=/usr/lib64/mysql
make
make install

头文件:/usr/local/include/mysql++

lib: /usr/local/lib
###so的配置
/etc/ld.so.conf /usr/local/lib

说明:mysql++的configure没有使用--enable-thread-check选项,因为我打算自己来管理多线程。
关于MySQL++多线程相关的内容可以看看http://tangentsoft.net/mysql++/doc/html/userman/threads.html。

 

#3.使用

主要使用的类有mysqlpp::Connection和mysqlpp::Query,前者用于跟mysql的连接,后者主要用于执行SQL语句。

##3.1 连接

示例代码:

bool throwExceptionOnError = false;
conn_ = new mysqlpp::Connection(throwExceptionOnError);

conn_->set_option(new mysqlpp::ReconnectOption(true));

bool success = conn_->connect(g_config->DbName_,
                                  g_config->DbServer_,
                                   g_config->DbUserName_,
                                  g_config->DbPassword_,
                                  g_config->DbPort_);
Connection

相关文章:

  • 2021-08-20
  • 2021-08-27
  • 2021-09-23
  • 2022-03-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-07
  • 2021-08-21
  • 2021-12-26
  • 2021-05-28
  • 2021-09-17
  • 2021-06-08
  • 2021-11-22
相关资源
相似解决方案