Possible Duplicate:
mysql_insert_id alternative for postgresql
Is there a Postgresql equivalent of mysql_insert_id() to get the ID generated in the last query ??
Possible Duplicate:
mysql_insert_id alternative for postgresql
Is there a Postgresql equivalent of mysql_insert_id() to get the ID generated in the last query ??
If you are using PostgreSQL 8.2 or newer then the simplest way is to use RETURNING
:
$result = pg_query($db, "INSERT INTO foo (bar) VALUES (123) RETURNING foo_id");
$insert_row = pg_fetch_row($result);
$insert_id = $insert_row[0];
For other alternatives see this duplicate.