c++ - 如何使用 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;
}
}
解决方案
推荐阅读
- python - 循环遍历 pandas 分组数据索引
- jquery - 呈现数据表列以忽略字母并按数字排序
- python - Python子进程:来回传递多个输入/输出
- reactjs - JSON输入错误的意外结束
- python - 将属性 pandas.DataFrame.shape 应用于存储在元组中的多个数据框
- vba - 删除值为零的数据标签然后重置 - VBA
- c# - 循环 HttpRequests 后如何重新排序项目
- mysql - MySQL 创建可以声明和设置选择结果的存储函数
- java - 如何停止工作 ScheduledExecutorService?
- python - 定义名称时 Python3 中的名称错误