Click here to Skip to main content
15,894,271 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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);
}


I have tried to debug, so I think method driver = get_driver_instance(); makes Wamp not working.
Posted

1 solution

Shouldn't it be

sql::mysql::MySQL_Driver *driver;
driver = sql::mysql::MySQL_Driver::get_mysql_driver_instance();


???
 
Share this answer
 
v2
Comments
Anh Ma Truong 17-Aug-10 5:35am    
I have tried to code like you, but it do not work. I hope receive your supports. Thank you very much.
Nyarost 17-Aug-10 5:38am    
I always used libmysqlclient with C API. This code was result of googling ;) May be you can try to dump driver variable and see what it contains.
Member 7715571 21-Jun-13 9:39am    
I also have same problem..Please sugest me too..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900