我需要C ++连接器的示例代码来设置“mysql_options”

时间:2016-03-21 01:43:00

标签: c++ mysql

如何使用mySQL C ++连接器设置超时? 我试过这个..但它是编译错误。

error: ‘class sql::Driver’ has no member named ‘mysql_options’
error: ‘MYSQL_READ_DEFAULT_FILE’ was not declared in this scope

代码在这里。

driver = get_driver_instance();
driver->mysql_options(MYSQL_READ_DEFAULT_FILE, "/my.cnf");
con = driver->connect(host, user, password);

我读了这页(http://dev.mysql.com/doc/refman/5.0/en/mysql-options.html) 但是这个页面没有C ++“Example”......

我需要帮助!

1 个答案:

答案 0 :(得分:1)

我自己找到了一种方法.. :) 它工作得很好。

    driver = get_driver_instance();

    sql::ConnectOptionsMap connection_properties;
    connection_properties ["hostName"] = host;
    connection_properties ["userName"] = user;
    connection_properties ["password"] = password;
    connection_properties ["OPT_CONNECT_TIMEOUT"] = 10;
    con = driver->connect(connection_properties);