Hi
I am trying to build an PHP extension for my personal project.
For some reason. I want to build some part of my project with extension.
So, I can make a connection via my extension as you can see below my c++
source code.
Cause of poor document, I confused with zend engine source code and c++ and
relations with php.
I just have a simple question, how can I use mysql funtions work with query
and process it like:
mysql_query
mysql_fetch_assoc
and ...
here is my code:
PHP_FUNCTION(ig_connect_to_
database)
{
zval fname, *args[3], dbLink;
zval selectDB, *args_selectDB[1], retval;
/*if(zend_call_method(NULL, NULL,
NULL,
"mysql_connect",
strlen("mysql_connect"),
&retval,
1,
args[1],
args[2] TSRMLS_CC
)
== FAILURE) {
php_printf("gosh!");
}
else {
php_printf("yep!");
}*/
ZVAL_STRING(&fname, "mysql_connect", 0);
MAKE_STD_ZVAL(args[0]);
ZVAL_STRING(args[0], "localhost", 1);
MAKE_STD_ZVAL(args[1]);
ZVAL_STRING(args[1], "root", 1);
MAKE_STD_ZVAL(args[2]);
ZVAL_STRING(args[2], "", 1);
if (call_user_function(EG(function_table), NULL, &fname, &dbLink, 3,
args TSRMLS_CC) == FAILURE) {
RETURN_STRING("fail to connect to database", 1);
}
else
{
zval_ptr_dtor(&args[2]);
zval_ptr_dtor(&args[1]);
zval_ptr_dtor(&args[0]);
/*
*return_value = dbLink;
zval_copy_ctor(return_value);
*/
/****now! I want to select a database on success****/
ZVAL_STRING(&selectDB, "mysql_select_db", 0);
MAKE_STD_ZVAL(args_selectDB[0]);
ZVAL_STRING(args_selectDB[0], "clickbartarirg", 1);
if (call_user_function(CG(function_table), NULL, &selectDB,
&retval, 1, args_selectDB TSRMLS_CC) == SUCCESS)
{
/* I successfully selected database */
ZEND_FETCH_RESOURCE_NO_RETURN(retval);
if(&retval)
{
php_printf("selected");
}
else
{
zend_error(E_ERROR, "failed to select database!");
}
zval_ptr_dtor(&args_selectDB[0]);
}
else
{
zend_error(E_ERROR, "database problem");
zval_ptr_dtor(&args_selectDB[0]);
}
}
}
Thanks.
Regards
*Amir Ghazavi*
*Web Developer
IT Manager of ECDC2013*
*
*
*www.ecdcconference.org*