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
hi,
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 ...
I would suggest to look at the mysqli driver, using mysqlnd as backend
instead of calling user land functions. Mysqlnd is the common
underlying layer for all mysql extensions.
Cheers,
Pierre
@pierrejoye
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 ...
Are you specifically referring to using mysql functions, or are you
referring to executing user space functions? It looks like you're
specifically referring to MySQL functions, and in that case, you should
look at ext/mysqlnd or libmysql. Executing user space functions in this
manner is not a good route to take.
In the PHP source directory, look at ext/mysqlnd/mysqlnd.h. This will
provide you with a C-level API.
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
it is no mater using mysql function or other function. I want to use both
as function in my extension.
I used PHP 5.2.9 so i have lib mysql instead of mysqlnd.
Is there any way to use lib mysql in c-Level API?
Regards
Amir Ghazavi
Web Developer
IT Manager of ECDC2013
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 ...Are you specifically referring to using mysql functions, or are you
referring to executing user space functions? It looks like you're
specifically referring to MySQL functions, and in that case, you should
look at ext/mysqlnd or libmysql. Executing user space functions in this
manner is not a good route to take.In the PHP source directory, look at ext/mysqlnd/mysqlnd.h. This will
provide you with a C-level API.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
Amir admin@ecdcconference.org wrote:
it is no mater using mysql function or other function. I want to use
both
as function in my extension.
It matters as calling userspace functions is in at least 90% of the cases the wrong approach and there are better ones. The better approach depends on the goal.
(The only times where it is a good thing to do is when calling a user provided callback as in usort()
or a method from an object extending an internal class s in some iterators etc.)
I used PHP 5.2.9 so i have lib mysql instead of mysqlnd.
This is very old. You should update.
Is there any way to use lib mysql in c-Level API?
libmysql is the MySQL Client Library. Refer to http://dev.mysql.com/doc/refman/5.5/en/c.html
johannes
It matters as calling userspace functions is in at least 90% of the cases
the wrong approach and there are better ones. The better approach depends
on the goal.
(The only times where it is a good thing to do is when calling a user
provided callback as inusort()
or a method from an object extending an
internal class s in some iterators etc.)
please explain me more about using userspace function problem of if other
one, or example how can I use string API from zend engine, not in php.
This is very old. You should update.
for some reson, I have to use PHP 5.2.9
everything is OK in PHP 5.3 but when I compile my source code from PHP
5.2.9 source code I got error:
microsoft visual studio 9.0\vc\include\sys\stat.inl(44) : error C2466:
cannot allocate an array of constant size 0
I did not find any appropriate answer for this error!
On Mon, Dec 10, 2012 at 3:55 AM, Johannes Schlüter
johannes@schlueters.dewrote:
Amir admin@ecdcconference.org wrote:
it is no mater using mysql function or other function. I want to use
both
as function in my extension.It matters as calling userspace functions is in at least 90% of the cases
the wrong approach and there are better ones. The better approach depends
on the goal.
(The only times where it is a good thing to do is when calling a user
provided callback as inusort()
or a method from an object extending an
internal class s in some iterators etc.)I used PHP 5.2.9 so i have lib mysql instead of mysqlnd.
This is very old. You should update.
Is there any way to use lib mysql in c-Level API?
libmysql is the MySQL Client Library. Refer to
http://dev.mysql.com/doc/refman/5.5/en/c.htmljohannes
hi,
It matters as calling userspace functions is in at least 90% of the cases
the wrong approach and there are better ones. The better approach depends
on the goal.
(The only times where it is a good thing to do is when calling a user
provided callback as inusort()
or a method from an object extending an
internal class s in some iterators etc.)please explain me more about using userspace function problem of if other
one, or example how can I use string API from zend engine, not in php.This is very old. You should update.
for some reson, I have to use PHP 5.2.9
everything is OK in PHP 5.3 but when I compile my source code from PHP
5.2.9 source code I got error:
microsoft visual studio 9.0\vc\include\sys\stat.inl(44) : error C2466:
cannot allocate an array of constant size 0I did not find any appropriate answer for this error!
Well, 5.2 is dead and never well supported VC9. The msdn documentation
will tell you how to fix this kind of error.
It matters as calling userspace functions is in at least 90% of the cases
the wrong approach and there are better ones. The better approach depends
on the goal.
(The only times where it is a good thing to do is when calling a user
provided callback as inusort()
or a method from an object extending an
internal class s in some iterators etc.)please explain me more about using userspace function problem of if other
one, or example how can I use string API from zend engine, not in php.
There is no string API in Zend. Depending on what you want using C
standard library string functions is way more efficient and simpler
doable than calling through all the layers of PHP ...
johannes