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


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to