首页 > 解决方案 > 如何使用 mysql-cppconn 中的 get_driver_instance_by_name(const char * const clientlib) 函数?

问题描述

我正在尝试在 phpcpp 中使用 mysql-cppconn 我第一次测试我可以在 C++ 中连接到 mydb 并且它通过了,我们将代码移动到 phpcpp 我有一个问题,get_driver_instance();认为这是由于我想使用的动态加载get_driver_instance_by_name function

  /* If dynamic loading is disabled in a driver then this function works just like get_driver_instance() */
  CPPCONN_PUBLIC_FUNC sql::Driver * get_driver_instance_by_name(const char * const clientlib);

我不知道这个功能需要什么输入,试图搜索并询问我认识的人但没有运气

我希望有人能帮助我理解这个功能,非常感谢

#include <phpcpp.h>
#include <iostream>

#include "mysql-cppconn/jdbc/mysql_connection.h"

#include <stdlib.h>
#include <sstream>
#include <stdexcept>

#include "mysql-cppconn/jdbc/mysql_connection.h"
#include <mysql-cppconn/jdbc/cppconn/driver.h>
#include <mysql-cppconn/jdbc/mysql_driver.h>
#include <mysql-cppconn/jdbc/cppconn/exception.h>
#include <mysql-cppconn/jdbc/cppconn/resultset.h>
#include <mysql-cppconn/jdbc/cppconn/statement.h>
#include <mysql-cppconn/jdbc/cppconn/prepared_statement.h>

#include <mysql-cppconn/mysql/jdbc.h>
#include <mysql-cppconn/mysqlx/common_constants.h>
void test_sql(){
    // try {
    sql::Driver *driver;
    sql::Connection *con;
    sql::Statement *stmt;
    sql::ResultSet *res;


    const string url=EXAMPLE_HOST;
    const string user=EXAMPLE_USER;
    const string pass=EXAMPLE_PASS;
    const string database=EXAMPLE_DB;


    sql::Driver* driver = get_driver_instance();

    const char * const clientlib = "MySQL_Driver";
    driver = get_driver_instance_by_name(MySQL_Driver);
}

/**
 *  tell the compiler that the get_module is a pure C function
 */
extern "C" {

    /**
     *  Function that is called by PHP right after the PHP process
     *  has started, and that returns an address of an internal PHP
     *  strucure with all the details and features of your extension
     *
     *  @return void*   a pointer to an address that is understood by PHP
     */
    PHPCPP_EXPORT void *get_module() 
    {
        // static(!) Php::Extension object that should stay in memory
        // for the entire duration of the process (that's why it's static)
        static Php::Extension extension("testsql", "1.0");

        // @todo    add your own functions, classes, namespaces to the extension
        extension.add("test_sql", test_sql);
        // return the extension
        return extension;
    }
}

标签: c++mysql

解决方案


推荐阅读