Re: Last ID Problem - Mailing list pgsql-novice

From Mitch Pirtle
Subject Re: Last ID Problem
Date
Msg-id 330532b605013111524d2c603@mail.gmail.com
Whole thread Raw
In response to Last ID Problem  (<operationsengineer1@yahoo.com>)
Responses Re: Last ID Problem
List pgsql-novice
On Mon, 31 Jan 2005 11:13:58 -0800 (PST),
operationsengineer1@yahoo.com <operationsengineer1@yahoo.com> wrote:
> -----------------------
>
> $cust = $_POST['cust']; // data entered
> $cust = addslashes($cust); // take care of slashes
>
> $db = &ADONewConnection('postgres');
> $db -> Connect($db_string,$db_owner,$db_pw,$db_name);
>
> $sql = "INSERT INTO customer (customer_name) VALUES
> ('$cust')"; // query to insert data - works fine.
>
> $id = "SELECT currval('cust_id')"; // used in an
> attempt to get last id (colum 'cust id')entered into
> db.
>
> $result = $db->Execute($sql);  // works fine.
>
> $id_result = $db->execute($id);  // $id_result has no
> value.
>
> ------------------------------

Why not first get the current value from the sequence, use it for your
INSERT statement, and then have it handy for the rest of the script?

    http://phplens.com/lens/adodb/docs-adodb.htm#inserted_id

-- Mitch

pgsql-novice by date:

Previous
From: Michael Fuhr
Date:
Subject: Re: How to learn Postgres?
Next
From: "Vishal Kashyap @ [SaiHertz]"
Date:
Subject: Re: Last ID Problem