note 2660 deleted from function.pg-exec by nlopess
| From: | nlopess@php.net | Date: | Sat, 26 Jun 2004 19:18:56 +0000 |
| Subject: | note 2660 deleted from function.pg-exec by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-71825@lists.php.net to get a copy of this message | ||
Note Submitter: jason@familynet.net
----
Insert returns an OID. Use the pg_GetLastOid() function to SELECT the last inserted row of your
session. To get an automatic serialized id, set up your table like this:
<PRE>
SQL:
CREATE TABLE something (
"itemno" int4 PRIMARY KEY DEFAULT NEXTVAL('serial'),
"name" varchar(80),
);
CREATE SEQUENCE serial INCREMENT 1 START 1;
PHP Example:
$result=pg_exec($conn,"INSERT INTO customer (name) VALUES ('test');");
if(!$result) {
error("Unable to update.");
}
else {
// display
$oid = pg_GetLastOid($result);
if($oid<0) error("bad news");
$result=pg_exec($conn,"SELECT itemno FROM customer WHERE oid = $oid;");
if(!$result) error("worse news");
$arr = pg_fetch_array ($result, 0);
echo "<p>ItemNo: $arr[0]</p>";
}
</PRE>