zoukankan      html  css  js  c++  java
  • C++操作MySQL,有用的朋友顶下,辛苦的原创啊. 天下 C++博客

    C++操作MySQL,有用的朋友顶下,辛苦的原创啊. - 天下 - C++博客

    向google大神搜 :
    mysql-connector

    http://www.mysql.com/products/connector/

    这些就是mysql所谓的连接器吧.
    一路向下看到:
    C++ Wrapper for MySQL C API (MySQL++) Download
    http://gna.org/projects/mysqlpp/
    下载手册慢慢慢慢看吧你.

    1. 先到http://tangentsoft.net/mysql++/ 下载mysql++源码.
    2. 将mysql++的VS2008的PRO打开后编译成msyqlpp.lib,mysqlpp.dll等几个动态或静态库。
    需要注意的是mysql的头文件及相关库文件需指定地方或加到VS工具的option->vc directories中.
    3.请把相应的DEBUG及RELEASE版本的DLL及LIB放到相应的目录.否则调试报异常.
    #include <afxwin.h>
    #include 
    <iostream>
    #include 
    "lib/mysql++.h"
    using namespace std;
    int main(){
        
    char name[50];
        mysqlpp::Connection conn(
    false);
        
    if (conn.connect("test","192.168.0.175","root","aaaaaa") ) {
            mysqlpp::Query SetCharacterSetQuery 
    = conn.query("SET names 'utf8'");
            SetCharacterSetQuery.exec(); 
    //注意这里还要SetCharacterSetQuery.exec() ,和C语言的API不同.
            mysqlpp::Query query = conn.query("select * from doc_threads");
            mysqlpp::StoreQueryResult res 
    = query.store();
            
    if (res) {
                cout 
    << res[0]["id"<< ' ' << CW2A(CA2W(res[0]["name"],CP_UTF8),CP_ACP) << ' ' <<endl;
                cout 
    << res[1]["id"<< ' ' << CW2A(CA2W(res[1]["name"],CP_UTF8),CP_ACP) << ' ' <<endl;
            }
        }
        conn.disconnect();
        
    return 0;
    }
  • 相关阅读:
    Ubuntu下 实现Linux与Windows的互相复制与粘贴
    bzoj2426
    bzoj1835
    bzoj1197
    bzoj1049
    bzoj2893
    bzoj1820
    bzoj1819
    bzoj1455
    bzoj3689
  • 原文地址:https://www.cnblogs.com/lexus/p/2949675.html
Copyright © 2011-2022 走看看