Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:25618 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 52461 invoked by uid 1010); 11 Sep 2006 20:00:17 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 52446 invoked from network); 11 Sep 2006 20:00:17 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Sep 2006 20:00:17 -0000 Authentication-Results: pb1.pair.com header.from=evan@coeus-group.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=evan@coeus-group.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain coeus-group.com from 68.230.241.36 cause and error) X-PHP-List-Original-Sender: evan@coeus-group.com X-Host-Fingerprint: 68.230.241.36 fed1rmmtao03.cox.net NetCache Data OnTap 5.x Received: from [68.230.241.36] ([68.230.241.36:51085] helo=fed1rmmtao03.cox.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E3/4A-02095-E40C5054 for ; Mon, 11 Sep 2006 16:00:16 -0400 Received: from fed1rmimpo01.cox.net ([70.169.32.71]) by fed1rmmtao03.cox.net (InterMail vM.6.01.06.01 201-2131-130-101-20060113) with ESMTP id <20060911200010.YOWM2704.fed1rmmtao03.cox.net@fed1rmimpo01.cox.net>; Mon, 11 Sep 2006 16:00:10 -0400 Received: from [192.168.1.101] ([68.111.223.160]) by fed1rmimpo01.cox.net with bizsmtp id M8001V00q3UFMYs0000000 Mon, 11 Sep 2006 16:00:01 -0400 Message-ID: <4505C049.8060405@coeus-group.com> Date: Mon, 11 Sep 2006 13:00:09 -0700 User-Agent: Thunderbird 1.5.0.5 (X11/20060728) MIME-Version: 1.0 To: internals@lists.php.net, Georg Richter References: <44F9CC6E.4020306@coeus-group.com> In-Reply-To: <44F9CC6E.4020306@coeus-group.com> Content-Type: multipart/mixed; boundary="------------080203000704070701050100" Subject: Re: [PATCH] mysqli interoperability From: evan@coeus-group.com (Evan Nemerson) --------------080203000704070701050100 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit It's been a while since I sent my original message, and nobody has replied, so I'm going to assume that I was simply too brief in my explanation (which, looking back, seems quite likely). Basically, I have a library, written in C, that uses a MySQL 5+ database. I've already written an extension for PHP to interface with my library, but I would like to have the ability to share a connection with mysqli. Here is a short snippet to show my extension (with this patch) works in PHP: $db = new mysqli('localhost', 'username', 'password', 'rdf'); $ts3db = new tstore($db); $query = 'SELECT ?person1, ?person2 WHERE { ?person1 ' . ' ?person2 }'; if ( ($res = $ts3db->query($query)) ) { // A successful result is a DOMDocument. echo $res->saveXML(); } Since now headers are installed from the mysqli extension, I currently have no way of getting a pointer to the MYSQL struct from the mysqli object passed to the tstore construct without copying code from the mysqli extension to my own, which obviously wouldn't be very robust to changes in the mysqli extension, or asking the user to point to the mysqli header file, which would only be available if they are compiling from source. My solution is to add a function to the mysqli extension which will accept a mysqli object zval and return a pointer to the MYSQL connection: MYSQL * mysqli_get_connection(zval *mysql_link, INTERNAL_FUNCTION_PARAMETERS); Once this function exists in the mysqli extension, I can copy the function prototype into my extension. I am confident that the prototype won't have to be changed in the future, mainly because of how simple it is. In order to properly detect failures, I've had to make a small modification outside of this new function which should have no impact on anything else, as well as a few minor changes to my function. These changes were not in my original patch, and the updated version is attached. If anyone has any questions, please let me know. -Evan Nemerson Evan Nemerson wrote: > Hi everyone, > > I'm working on an extension for an RDF triple store that is built on top > of MySQL 5+, and I'd like to be able to share the MySQL connection with > mysqli. Unfortunately, since the mysqli header isn't installed, I can't > seem to find a way that could withstand changes in mysqli. > > What I've come up with is to create a trivial function which will take a > (zval *) and return a (MYSQL *). I know it's a bit of a hack, but I was > trying to be as unintrusive as possible. > > Patch is attached. > > -Evan Nemerson --------------080203000704070701050100 Content-Type: text/x-patch; name="mysqli_interop.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="mysqli_interop.diff" Index: php_mysqli.h =================================================================== RCS file: /repository/php-src/ext/mysqli/php_mysqli.h,v retrieving revision 1.60 diff -u -r1.60 php_mysqli.h --- php_mysqli.h 9 May 2006 11:27:20 -0000 1.60 +++ php_mysqli.h 11 Sep 2006 19:54:27 -0000 @@ -221,11 +221,11 @@ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't fetch %s", intern->zo.ce->name);\ RETURN_NULL();\ }\ - __ptr = (__type)my_res->ptr; \ if (__check && my_res->status < __check) { \ php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid object or resource %s\n", intern->zo.ce->name); \ RETURN_NULL();\ }\ + __ptr = (__type)my_res->ptr; \ } #define MYSQLI_SET_STATUS(__id, __value) \ Index: mysqli.c =================================================================== RCS file: /repository/php-src/ext/mysqli/mysqli.c,v retrieving revision 1.97 diff -u -r1.97 mysqli.c --- mysqli.c 27 Jul 2006 10:53:03 -0000 1.97 +++ mysqli.c 11 Sep 2006 19:54:29 -0000 @@ -331,6 +331,16 @@ } /* }}} */ +/* {{{ MYSQL * mysqli_get_connection(zval *mysql_link TSRMLS_DC) */ +MYSQL * mysqli_get_connection(zval *mysql_link, INTERNAL_FUNCTION_PARAMETERS) { + MY_MYSQL *mysql = NULL; + + MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID); + + return mysql ? mysql->mysql : NULL; +} +/* }}} */ + static union _zend_function *php_mysqli_constructor_get(zval *object TSRMLS_DC) { mysqli_object *obj = (mysqli_object *)zend_objects_get_address(object TSRMLS_CC); --------------080203000704070701050100--