note 13614 added to function.mysql-insert-id.php
| From: | mark at wildrhino dot com | Date: | Sun, 24 Jun 2001 20:38:14 +0000 |
| Subject: | note 13614 added to function.mysql-insert-id.php | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-14609@lists.php.net to get a copy of this message | ||
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.
http://www.php.net/manual/en/function.mysql-insert-id.php