Re: Last ID Problem

From: <operationsengineer1(at)yahoo(dot)com>
To: Mitch Pirtle <mitch(dot)pirtle(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Last ID Problem
Date: 2005-01-31 21:01:52
Message-ID: 20050131210152.27092.qmail@web52409.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-novice

mitch, i tried insert_id(), however, the following...

print "Query Success! The new row has an id of: " .
$db->Insert_Id();

produced...

"Query Success! The new row has an id of: 0"

every time.

reading your suggestion, though, leads me to believe
that geting insert_id() BEFORE running the the query
may impact the results.

can you point me to a simple code example of the whole
process?

also, i recall reading something about insert_id() not
working if the db connection wasn't persistent.

--- Mitch Pirtle <mitch(dot)pirtle(at)gmail(dot)com> wrote:

> 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
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 2: you can get off all lists at once with the
> unregister command
> (send "unregister YourEmailAddressHere" to
> majordomo(at)postgresql(dot)org)
>


__________________________________
Do you Yahoo!?
Yahoo! Mail - now with 250MB free storage. Learn more.
http://info.mail.yahoo.com/mail_250

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Dave Page 2005-01-31 21:30:35 Re: 7.2.7 -> 8.0.1 Bundles Ready ...
Previous Message Tom Lane 2005-01-31 20:23:59 Re: Allow GRANT/REVOKE permissions to be applied to all schema objects with one command

Browse pgsql-novice by date

  From Date Subject
Next Message Mitch Pirtle 2005-01-31 22:50:33 Re: Last ID Problem
Previous Message Vishal Kashyap @ [SaiHertz] 2005-01-31 20:18:53 Re: Last ID Problem