note 83440 added to pdo.lastinsertid

From: Date: Mon, 26 May 2008 16:05:19 +0000
Subject: note 83440 added to pdo.lastinsertid
Groups: php.notes 
Request: Send a blank email to php-notes+get-139797@lists.php.net to get a copy of this message
In response to Yonatan Ben-Nes, it does appear that using the latest versions of PHP 5.x and PostgreSQL 8.x, the driver will return a "meaningful" ID (rather than an OID), provided you pass the name of the corresponding sequence. So, if you created a table as follows: CREATE TABLE "user" ( "id" SERIAL PRIMARY KEY NOT NULL, "username" character varying(32) ); PostgreSQL will (by default) create a sequence called 'user_id_seq'. You can then do something like: $strTable = "user": $last_insert_id = $objPDO->lastInsertId("$strTable_id_seq); This does appear to function as expected. What is a little unclear to me is whether this simply returns the current value of the sequence; if it does, this isn't a particularly reliable indicator as to the id of the record your code just inserted, especially if your site or application is especially high traffic. ---- Server IP: 92.48.74.199 Probable Submitter: 82.70.151.222 ---- Manual Page -- http://www.php.net/manual/en/pdo.lastinsertid.php Edit -- https://master.php.net/note/edit/83440 Del: integrated -- https://master.php.net/note/delete/83440/integrated Del: useless -- https://master.php.net/note/delete/83440/useless Del: bad code -- https://master.php.net/note/delete/83440/bad+code Del: spam -- https://master.php.net/note/delete/83440/spam Del: non-english -- https://master.php.net/note/delete/83440/non-english Del: in docs -- https://master.php.net/note/delete/83440/in+docs Del: other reasons-- https://master.php.net/note/delete/83440 Reject -- https://master.php.net/note/reject/83440 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#139797) next »