note 29293 added to function.pg-last-oid
| From: | bens at effortlessis dot com | Date: | Sat, 08 Feb 2003 23:39:44 +0000 |
| Subject: | note 29293 added to function.pg-last-oid | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-43666@lists.php.net to get a copy of this message | ||
Especially now with an optional oid field, getting an implicit serial key is harder than ever. The
solution is to get the serial key first, and then use that value in an insert:
<?
pg_query($conn, 'CREATE TABLE foo (key SERIAL, foo TEXT)');
$res=pg_query("SELECT nextval('foo_key_seq') as key");
$key=pg_fetch_array($res, 0);
$key=$key[key];
// now we have the serial value in $key, let's do the insert
pg_query("INSERT INTO foo (key, foo) VALUES ($key, 'blah blah')");
?>
Hope this helps...
--
http://www.php.net/manual/en/function.pg-last-oid.php
http://master.php.net/manage/user-notes.php?action=edit+29293
http://master.php.net/manage/user-notes.php?action=delete+29293
http://master.php.net/manage/user-notes.php?action=reject+29293