mysql: mysql++的安装与使用

原:http://hi.baidu.com/ismayday/blog/item/9e4ec75c63491f45fbf2c0b8.html

LINUX系统下MYSQL++的安装及使用

测试版本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
   
测试:

//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++ -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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值