note 82838 added to function.PDO-lastInsertId

From: Date: Mon, 28 Apr 2008 17:17:29 +0000
Subject: note 82838 added to function.PDO-lastInsertId
Groups: php.notes 
Request: Send a blank email to php-notes+get-138877@lists.php.net to get a copy of this message
It should be noted here at this function will not display the correct ID if issuing ON DUPLICATE KEY UPDATE. Example on a new Row: <?php $sql = "INSERT INTO city (city) VALUES ('Paris') ON DUPLICATE KEY UPDATE city = 'Paris"; $dbh->query($sql); echo $dbh->lastInsertId(); ?> Above displays: 1 Expected display: 1 Example on an existing row that gets updated: <?php $sql = "INSERT INTO city (city) VALUES ('Paris') ON DUPLICATE KEY UPDATE city = 'Paris"; $dbh->query($sql); echo $dbh->lastInsertId(); ?> Above displays: 2 Expected display: 1 (since no new records were inserted) You'll have to work around this. ---- Server IP: 217.160.250.20 Probable Submitter: 216.68.93.99 ---- Manual Page -- http://www.php.net/manual/en/function.PDO-lastInsertId.php Edit -- https://master.php.net/note/edit/82838 Del: integrated -- https://master.php.net/note/delete/82838/integrated Del: useless -- https://master.php.net/note/delete/82838/useless Del: bad code -- https://master.php.net/note/delete/82838/bad+code Del: spam -- https://master.php.net/note/delete/82838/spam Del: non-english -- https://master.php.net/note/delete/82838/non-english Del: in docs -- https://master.php.net/note/delete/82838/in+docs Del: other reasons-- https://master.php.net/note/delete/82838 Reject -- https://master.php.net/note/reject/82838 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#138877) next »