Skip site navigation (1) Skip section navigation (2)

Re: Last ID Problem

From: Mitch Pirtle <mitch(dot)pirtle(at)gmail(dot)com>
To: "operationsengineer1(at)yahoo(dot)com" <operationsengineer1(at)yahoo(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Last ID Problem
Date: 2005-01-31 19:52:08
Message-ID: 330532b605013111524d2c603@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-hackerspgsql-novice
On Mon, 31 Jan 2005 11:13:58 -0800 (PST),
operationsengineer1(at)yahoo(dot)com <operationsengineer1(at)yahoo(dot)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

In response to

Responses

pgsql-novice by date

Next:From: Vishal Kashyap @ [SaiHertz]Date: 2005-01-31 20:18:53
Subject: Re: Last ID Problem
Previous:From: Michael FuhrDate: 2005-01-31 19:46:01
Subject: Re: How to learn Postgres?

pgsql-hackers by date

Next:From: Marc G. FournierDate: 2005-01-31 20:14:45
Subject: New 7.2.7 Bundle Up
Previous:From: Merlin MoncureDate: 2005-01-31 19:45:39
Subject: Re: Allow GRANT/REVOKE permissions to be applied to all schema objects with one command

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group