note 115739 added to pdo.lastinsertid

From: Date: Tue, 16 Sep 2014 07:19:42 +0000
Subject: note 115739 added to pdo.lastinsertid
Groups: php.notes 
Request: Send a blank email to php-notes+get-200452@lists.php.net to get a copy of this message
Sorry to contradict Jonathon Hibbard's comment (http://php.net/manual/en/pdo.lastinsertid.php#82838), but my experiencie with INSERT INTO ... ON DUPLICATE KEY UPDATE is totally different; maybe it's due to PHP version (I'm on Windows, 5.4.7; I realize his post is 6 years old) or to the database engine (MySQL in my case). Nevertheless, if I do an INSERT INTO ... ON DUPLICATE KEY UPDATE (something like id=id or equivalent, where the updated value is equal to the original one), this is what I'm getting: - If the key didn't exist, the value is inserted, and lastInsertId() returns the expected id for the new row. - If the row exists AND a value is updated, with lastInsertId() I get the ID of the updated row. - If the row exists but NO value is updated, lastInsertId() returns 0. That contradicts his example, where he assures that "INSERT INTO city (city) VALUES ('Paris') ON DUPLICATE KEY UPDATE city = 'Paris'" returns 2 (??) on lastInsertId() and that he expected to return 1 "since no records were inserted" (??). Hope this helps someone. ---- Server IP: 72.52.91.14 Probable Submitter: 62.43.206.58 ---- Manual Page -- http://php.net/manual/en/pdo.lastinsertid.php Edit -- https://master.php.net/note/edit/115739 Del: integrated -- https://master.php.net/note/delete/115739/integrated Del: useless -- https://master.php.net/note/delete/115739/useless Del: bad code -- https://master.php.net/note/delete/115739/bad+code Del: spam -- https://master.php.net/note/delete/115739/spam Del: non-english -- https://master.php.net/note/delete/115739/non-english Del: in docs -- https://master.php.net/note/delete/115739/in+docs Del: other reasons-- https://master.php.net/note/delete/115739 Reject -- https://master.php.net/note/reject/115739 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#200452) next »