note 13614 deleted from function.mysql-insert-id by tomsommer

From: Date: Sun, 04 Apr 2004 01:25:28 +0000
Subject: note 13614 deleted from function.mysql-insert-id by tomsommer
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-67599@lists.php.net to get a copy of this message
Note Submitter: mark@wildrhino.com ---- Note that mysql_insert_id may not do exactly what you expect for insert ignore statements (mysql version 3.23.31): mysql> CREATE TABLE test -> ( -> ID MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, -> stuff VARCHAR(255), -> UNIQUE stuff (stuff) -> ) -> ; Query OK, 0 rows affected (0.01 sec) mysql> SELECT LAST_INSERT_ID(); +------------------+ | last_insert_id() | +------------------+ | 0 | +------------------+ 1 row in set (0.00 sec) mysql> INSERT IGNORE INTO test (stuff) VALUES ('some_stuff'); Query OK, 1 row affected (0.00 sec) mysql> SELECT LAST_INSERT_ID(); +------------------+ | last_insert_id() | +------------------+ | 1 | +------------------+ 1 row in set (0.00 sec) mysql> INSERT IGNORE INTO test (stuff) VALUES ('some_stuff'); Query OK, 0 rows affected (0.00 sec) mysql> SELECT LAST_INSERT_ID(); +------------------+ | last_insert_id() | +------------------+ | 2 | +------------------+ 1 row in set (0.00 sec) mysql> SELECT * FROM test WHERE id=2; Empty set (0.01 sec) This appears to be a bug / feature in mysql 3.23.31 (untested on other versions) rather than PHP.

« previous php.notes (#67599) next »