Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:64197 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 92721 invoked from network); 8 Dec 2012 06:23:48 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Dec 2012 06:23:48 -0000 Authentication-Results: pb1.pair.com smtp.mail=mohammad.ghazavi@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=mohammad.ghazavi@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.174 as permitted sender) X-PHP-List-Original-Sender: mohammad.ghazavi@gmail.com X-Host-Fingerprint: 209.85.223.174 mail-ie0-f174.google.com Received: from [209.85.223.174] ([209.85.223.174:51672] helo=mail-ie0-f174.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 74/1F-14797-0DCD2C05 for ; Sat, 08 Dec 2012 01:23:12 -0500 Received: by mail-ie0-f174.google.com with SMTP id c11so3522002ieb.33 for ; Fri, 07 Dec 2012 22:23:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type; bh=uT69R6UPcTbDzt6NtHnuv87VvpxKtA2VU850pZW5igI=; b=zwzf+l3lFeK2+6rUAQo3CuAjHc1LBBCBk1wSWqYmT+W9GO2ZmViGex7jUmgOKhCLPE d2guBf8JQvZuRBDS+dMXimudUby3NzME+CmuYXB/31IpecXczl8z/X5b2h8rVqI6vyAc fdVfN6KyVqw2w6YC4DrEmIMBWMKNnfQZzbDXvw0KtS3OH0uYkNYz/xMliXB425WU1Q3A ZMHEtGYbKDfldxjT/p1brRWniP7NT9WG3tyY+qPCEXw+k6rdF3egvVgusGWafty9knQ9 yJW2MvOhAnbbUKlN75tGP81W5biM1YsYd8OwlRIKUCdNTVac2Xn+XTTkkX4vndIKX3ES xNVQ== Received: by 10.50.40.201 with SMTP id z9mr1159503igk.59.1354947789549; Fri, 07 Dec 2012 22:23:09 -0800 (PST) MIME-Version: 1.0 Sender: mohammad.ghazavi@gmail.com Received: by 10.50.156.163 with HTTP; Fri, 7 Dec 2012 22:22:29 -0800 (PST) In-Reply-To: References: Date: Sat, 8 Dec 2012 09:52:29 +0330 X-Google-Sender-Auth: _ed7VWI0ZMslOChAqLJViW5qXSA Message-ID: To: Will Fitch Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary=14dae9340ca7af71a704d0515dbf Subject: Re: [PHP-DEV] a simple question about PHP extension: using user function in my own extension From: admin@ecdcconference.org (Amir) --14dae9340ca7af71a704d0515dbf Content-Type: text/plain; charset=UTF-8 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 wrote: > On Wed, Dec 5, 2012 at 6:18 AM, Amir 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* >> > > --14dae9340ca7af71a704d0515dbf--