note 42561 rejected from function.pg-last-oid by betz
| From: | betz@php.net | Date: | Fri, 21 May 2004 14:34:40 +0000 |
| Subject: | note 42561 rejected from function.pg-last-oid by betz | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-69909@lists.php.net to get a copy of this message | ||
Note Submitter: silvio.g@unipg.it
----
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.