PHP扩展连接到Mysql [英] PHP extension connect to Mysql
本文介绍了PHP扩展连接到Mysql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图用C ++和MySQL连接器连接MySQL.我简单的PHP扩展"Hello World"正常运行,但是当我添加了访问MySQL的功能时,Wamp无法正常工作.希望得到您的支持.非常感谢您,我的英语水平很抱歉.我的代码如下.
I have tried to connect MySQL with C++ and MySQL connector. My simple PHP extension "Hello World" run normally, but when I added a function to access MySQL, so Wamp not working. I hope receice your supports. Thank you very much, I am sorry about my English skill. My code like follow.
// dll_ver_01.cpp : Defines the exported functions for the DLL application.
//
#include "stdafx.h"
ZEND_FUNCTION(fetch_talkphp_links);
ZEND_FUNCTION(haha);
zend_function_entry dll_ver_01_functions[] = {
//ZEND_FE(fetch_talkphp_links, NULL)
ZEND_FE(haha, NULL)
{NULL, NULL, NULL}
};
zend_module_entry dll_ver_01_module_entry = {
STANDARD_MODULE_HEADER,
"dll_ver_01",
dll_ver_01_functions,
NULL, NULL, NULL, NULL, NULL,
"1.0",
STANDARD_MODULE_PROPERTIES
};
ZEND_GET_MODULE(dll_ver_01);
ZEND_FUNCTION(fetch_talkphp_links)
{
bool useHtml = false;
char *link = "";
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &useHtml) == FAILURE)
{
RETURN_STRING("Missing Parameter", true);
}
if (useHtml == true)
{
link = "<a href=\"http://www.google.com.vn\">Google</a>";
}
else
{
link = "http://www.google.com.vn";
}
RETURN_STRING(link, true);
}
PHP_FUNCTION(haha)
{
sql::Driver *driver;
sql::Connection *con;
sql::Statement *stmt;
sql::ResultSet *res;
driver = get_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306","root","");
/*try{
//khoi tao 1 connection
//driver = get_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306","root","");
//chon db
con->setSchema("ql_laptop");
stmt = con->createStatement();
//truy van don gian
stmt->execute("INSERT INTO admin(MaAdmin, Password, Ten, Loai) VALUES (''hehehe'', ''a'', ''aaaaaa'', 1)");
}
catch(sql::SQLException &e)
{
RETURN_STRING("ma truong anh",true);
}
RETURN_STRING("ma truong anh",true);
//giai phong con tro
delete stmt;
delete con;*/
RETURN_STRING("ma truong anh",true);
}
我已经尝试调试,所以我认为方法 driver = get_driver_instance(); 使Wamp无法正常工作.
I have tried to debug, so I think method driver = get_driver_instance(); makes Wamp not working.
推荐答案
应该be
Shouldn''t it be
sql::mysql::MySQL_Driver *driver;
driver = sql::mysql::MySQL_Driver::get_mysql_driver_instance();
???
???
这篇关于PHP扩展连接到Mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文