note 42561 added to function.pg-last-oid

From: Date: Fri, 21 May 2004 10:47:45 +0000
Subject: note 42561 added to function.pg-last-oid
Groups: php.notes 
Request: Send a blank email to php-notes+get-69903@lists.php.net to get a copy of this message
Excuse me, but i need urgent help: I have this function: function pg_insert_id($pg_res, $serial_column, $table) { global $link; $oid = pg_last_oid($pg_res); $query = "SELECT $serial_column FROM $table WHERE oid = $oid"; $result = pg_query($link, $query); $row = pg_fetch_row($result, 0); return($row[0]); } In the main function i open a transaction, I insert a record, i use the function pg_insert_id to get the value of the id of the inserted record (id=primary key (serial)) and then i use this value to insert a record in another table. Finally, if everything is ok, I commit the transaction. Now think about 50 users using this code... does pg_last_oid get the oid of my inserted record, or does it get the oid of a record inserted from another insert query of another transaction that committed before i committed my trasaction? Thanks in advance. P.S.: I have PostgreSQL 7.3.4 and PHP 4.3.3 and my tables are with OIDS. ---- Manual Page -- http://www.php.net/manual/en/function.pg-last-oid.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+42561 Delete -- http://master.php.net/manage/user-notes.php?action=delete+42561&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+42561&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#69903) next »