3

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

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

不过好像很难。有没有其他教程。请告诉我。

4

1 回答 1

1

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

     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");
于 2012-03-05T12:25:41.770 回答