Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:55230 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 16946 invoked from network); 5 Sep 2011 15:07:31 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Sep 2011 15:07:31 -0000 Authentication-Results: pb1.pair.com header.from=php@hristov.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=php@hristov.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain hristov.com from 91.196.124.214 cause and error) X-PHP-List-Original-Sender: php@hristov.com X-Host-Fingerprint: 91.196.124.214 more.superhosting.bg Linux 2.6 Received: from [91.196.124.214] ([91.196.124.214:43499] helo=more.superhosting.bg) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3C/E8-64330-2B5E46E4 for ; Mon, 05 Sep 2011 11:07:31 -0400 Received: from androto.ddns.playtime.bg ([87.121.162.167] helo=[192.168.2.117]) by more.superhosting.bg with esmtpa (Exim 4.69) (envelope-from ) id 1R0ali-0001Go-RH; Mon, 05 Sep 2011 18:07:26 +0300 Message-ID: <4E64E5AC.4040805@hristov.com> Date: Mon, 05 Sep 2011 17:07:24 +0200 User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.21) Gecko/20110831 Thunderbird/3.1.13 ThunderBrowse/3.8 MIME-Version: 1.0 To: Ulf Wendel CC: internals@lists.php.net References: <4E611027.6000103@sugarcrm.com> <4E64E25E.3080102@oracle.com> In-Reply-To: <4E64E25E.3080102@oracle.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - more.superhosting.bg X-AntiAbuse: Original Domain - lists.php.net X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - hristov.com X-Source: X-Source-Args: X-Source-Dir: Subject: Re: [PHP-DEV] mysqli tests breaking From: php@hristov.com (Andrey Hristov) Hi, On 09/05/2011 04:53 PM, Ulf Wendel wrote: > This is the one and only mysqlnd-libmysql difference of some practical > relevance. I consider it at least questionable if libmysql is correct. > > If it was to be decided that mysqlnd is wrong, it is probably like five > lines of code in mysqlnd to change, if need be. > > > Am 02.09.2011 19:19, schrieb Stas Malyshev: >> API vs. SQL LAST_INSERT_ID() >> [ext/mysqli/tests/mysqli_last_insert_id.phpt] >> The reason is that this test relies on LAST_INSERT_ID() being reset on >> SELECT. I have not observed such behavior neither via PHP not talking to >> Mysql server directly from CLI interface, so I have no idea why this >> test assumes such behavior. > > Personal observation and memory may not be the best reference here. What > the test does is: > > DROP TABLE IF EXISTS test > CREATE TABLE test(id INT AUTO_INCREMENT PRIMARY KEY) Engine=MyISAM > > INSERT INTO test(id) VALUES (1); > printf("insert id for INSERT is: %d\n", mysqli_insert_id(link)); > > SELECT 1 FROM DUAL > printf("insert id for SELECT is: %d\n", mysqli_insert_id(link)); > > > Libmysql will print: > > insert id for INSERT is: 1 > insert id for SELECT is: 1 and here we see a bug. The value in libmysql is not reset, as the Documentation states. Clear bug. > Mysqlnd will print: > > insert id for INSERT is: 1 > insert id for SELECT is: 0 > mysqlnd does what is expected, as in many other cases :) During mysqlnd's development we found numerous bugs in libmysql and reported them. mysqlnd provided support for multiple result sets from prepared statements more than year earlier than libmysql even had code to handle this, which is in MySQL 5.5 now. > > "mysql_insert_id() returns 0 if the previous statement does not use an > AUTO_INCREMENT value. If you need to save the value for later, be sure > to call mysql_insert_id() immediately after the statement that generates > the value." > Very clearly said. LAST_INSERT_ID() is another story, but it has nothing to do with the client library. Andrey