|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-09-06 15:55 UTC] jani@php.net
[2008-09-14 01:00 UTC] php-bugs at lists dot php dot net
[2009-09-01 14:14 UTC] chuck dot joga at windriver dot com
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Dec 06 22:00:02 2025 UTC |
Description: ------------ I execute the following query: INSERT INTO test VALUES (NULL,'key','value') ON DUPLICATE KEY UPDATE v='value'; key exists and value of v column is the same as new value in UPDATE clause. I call $id=mysql_insert_id(); and expect that $id is id of existing row (id is INT NOT NULL PRIMARY KEY AUTO_INCREMENT column) but $id contains another value. MySQL version is 5.0.51a Reproduce code: --------------- <?php /* MySQL table definition CREATE TABLE test ( id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, k VARCHAR(10) NOT NULL UNIQUE, v VARCHAR(10) NOT NULL ); */ $db_host='localhost'; //database host $db_user=''; //database user $db_pass=''; //database password $db_name='test'; //database name mysql_connect($db_host,$db_user,$db_pass); //connect to database mysql_query("USE $db_name"); //select database mysql_query('TRUNCATE test'); //clear test table mysql_query('INSERT INTO test VALUES (NULL,\'key\',\'value\')'); mysql_query('INSERT INTO test VALUES (NULL,\'key\',\'value\') ON DUPLICATE KEY UPDATE v=\'value\''); $id=mysql_insert_id(); mysql_close(); echo("Expected id is 1, id is $id\n"); ?> Expected result: ---------------- I expect $id to be 1 Actual result: -------------- $id is 2