Re: a simple question about PHP extension: using user function in my own extension
| From: | Amir | Date: | Sat, 08 Dec 2012 06:22:29 +0000 |
| Subject: | Re: a simple question about PHP extension: using user function in my own extension | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-64197@lists.php.net to get a copy of this message | ||
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*
*
*
*www.ecdcconference.org*
On Thu, Dec 6, 2012 at 1:17 AM, Will Fitch <wfitch@meetme.com> wrote:
> On Wed, Dec 5, 2012 at 6:18 AM, Amir <admin@ecdcconference.org> wrote:
>
>> 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*
>> *
>> *
>> *www.ecdcconference.org*
>>
>
>