Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:64163 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 43041 invoked from network); 5 Dec 2012 21:47:51 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Dec 2012 21:47:51 -0000 Authentication-Results: pb1.pair.com header.from=wfitch@meetme.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=wfitch@meetme.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain meetme.com designates 74.125.149.238 as permitted sender) X-PHP-List-Original-Sender: wfitch@meetme.com X-Host-Fingerprint: 74.125.149.238 na3sys009aog115.obsmtp.com Linux 2.5 (sometimes 2.4) (4) Received: from [74.125.149.238] ([74.125.149.238:50184] helo=na3sys009aog115.obsmtp.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 46/D8-04278-501CFB05 for ; Wed, 05 Dec 2012 16:47:50 -0500 Received: from mail-vb0-f71.google.com ([209.85.212.71]) (using TLSv1) by na3sys009aob115.postini.com ([74.125.148.12]) with SMTP ID DSNKUL/BAqiqU9gD9XkJoAPpofiyuHNXDVWs@postini.com; Wed, 05 Dec 2012 13:47:49 PST Received: by mail-vb0-f71.google.com with SMTP id p1so3912427vbi.2 for ; Wed, 05 Dec 2012 13:47:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-originating-ip:in-reply-to:references:date :message-id:subject:from:to:cc:content-type:x-gm-message-state; bh=al1CSNu8eQbrbqkfpBYTh7SQx1cQZ5QNHZtCTueXvS0=; b=m3Zyw46HsvntKZZIgxcBO/tWxFnv3oGeHa8WqB43JeFiGLVZukbiKL152CEczGVbH/ DM641lxCsjMaJjjet1yMIgKq5+K9SdeRJCosAo0Sw+flzJ04x+hZGpc55e6EPJ5x3gnz fMk/PEhgmYNCRUVHrBDG8sOVeMEUrXtIwBLiJjlbJCjLMwX3lg/p/ubns9GjxbHShF21 o3tNhSSItNujTrg/6Q1VCC6325ku0zdCpanizqPndSDjaP3unnFA58bWJEJjUSRYJq02 b7rr3gKhuM2uEUUCUxOl5EBRb53cpPqaMp6hEg8IPxlbnMN/mJ7HLSDpYTGZgeThR2WG oSvw== Received: by 10.52.88.168 with SMTP id bh8mr10830477vdb.51.1354744065976; Wed, 05 Dec 2012 13:47:45 -0800 (PST) MIME-Version: 1.0 Received: by 10.52.88.168 with SMTP id bh8mr10830474vdb.51.1354744065874; Wed, 05 Dec 2012 13:47:45 -0800 (PST) Received: by 10.58.225.71 with HTTP; Wed, 5 Dec 2012 13:47:45 -0800 (PST) X-Originating-IP: [204.145.120.11] In-Reply-To: References: Date: Wed, 5 Dec 2012 16:47:45 -0500 Message-ID: To: Amir Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary=bcaec5016079cedcff04d021ee1f X-Gm-Message-State: ALoCoQk+atO4RlVF3CMxmqsgR5X7qt9/AuoJddFZUTq7/KP1DDj/U7ukpFmecFwuZAKin6H+ajpfkJbu0NTsDKlTacVy9o2z+4AYnnUcZtJZrKivid084aA6R8K/oDrBPAzv2tWQBCHYKm8NvFeTW8TixDfoA6l8Nwpu5JNLSnNkcHRahuv2y3E= Subject: Re: [PHP-DEV] a simple question about PHP extension: using user function in my own extension From: wfitch@meetme.com (Will Fitch) --bcaec5016079cedcff04d021ee1f Content-Type: text/plain; charset=ISO-8859-1 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* > --bcaec5016079cedcff04d021ee1f--