Как я могу использовать функцию get_driver_instance_by_name (const char * const clientlib) из mysql -cppconn? - PullRequest
1 голос
/ 12 марта 2020

Я пытаюсь использовать mysql -cppconn в phpcpp. Сначала я проверил, могу ли я подключиться к mydb в c ++, и все прошло, перемещая код в phpcpp У меня была проблема с get_driver_instance(); мышлением это было связано с динамической c загрузкой, которую я хочу использовать 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;
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...