c++ - mysql连接器的使用方法

标签 c++ mysql linux connector

我想为 mysql 数据库使用连接器。我关注这个页面

http://dev.mysql.com/tech-resources/articles/mysql-connector-cpp.html

但是好像很难。有没有其他教程。请告诉我。

最佳答案

示例代码的相关部分非常简单:

     Driver *driver;
     Connection *con;
     Statement *stmt;
     ResultSet *res;

    driver = get_driver_instance();

    /* create a database connection using the Driver */
    con = driver -> connect(url, user, password);

    /* alternate syntax using auto_ptr to create the db connection */
    //auto_ptr  con (driver -> connect(url, user, password));

    /* turn off the autocommit */
    con -> setAutoCommit(0);

    /* select appropriate database schema */
    con -> setSchema(database);

从那里你只需要像这样查询它:

     stmt = con -> createStatement();

     res = stmt -> executeQuery ("SELECT * FROM City");

关于c++ - mysql连接器的使用方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9565121/

相关文章:

c++ - 对于具有线程模型两者的对象,COM 编码是否(永远)是必需的?

c++ - 如何在 constexpr 函数内部的字符串文字上静态断言条件?

mysql - 创建数字和字母混合主键

PHP/MYSQL - 可以在 mysql 字段值中使用 php 变量吗?

linux - 必需选项 getopts linux

c++ - 在 LINUX 上使用 C++ 的 LAPACK/LAPACKE --- 编译、链接和运行?

linux - 我如何在 ubuntu linux 中流水线化两个通过串行端口共享数据的程序?

c++ - 将值放入二维数组

c++ - 将代码块用于 const unsigned long 时出现 GCC 错误

mysql - 获取某个时间范围内 2 个日期的特定数据