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 23:33:02
Message-ID: 20050131233302.26671.qmail@web52407.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-novice

thanks mitch...

i ahve the following code...

$cust = $_POST['cust'];
$cust = addslashes($cust);
$db = &ADONewConnection('postgres');
$db -> Connect($db_string,$db_owner,$db_pw,$db_name);
$sql = "INSERT INTO customer (customer_name) VALUES
('$cust')";
$result = $db->Execute($sql);
$insert_id = $db->getone("select currval('cust_id')");

if ($result === false)
{
print $db->ErrorMsg();
exit();
}
else
{
$dbreturn = 'Passed';
print $dbreturn;
print $insert_id;
exit();
}

it prints $dbreturn as "Passed", but it does not print
any value for insert_id. i'm trying to see this value
and verify it is working correctly before trying
anything more complex.

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

> This is the easiest way to do it:
>
>
>
http://ask.slashdot.org/article.pl?sid=05/01/31/1441200&from=rss
>
> This is using plain old SQL the PostgreSQL way ;-)
>
> Basically you:
>
> 1) get the next number from the sequence
> 2) do the update
> 3) use that number for related table insterts
>
> For an ADOdb example, this thread:
>
>
> http://www.phparch.com/discuss/index.php/t/372/0/
>
> Says to use this syntax:
>
> $insert_id = $db->getone("select
> currval('sequence_name')");
>
> -- Mitch
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 9: the planner will ignore your desire to choose
> an index scan if your
> joining column's datatypes do not match
>


__________________________________
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 Mitch Pirtle 2005-02-01 00:58:42 Re: Last ID Problem
Previous Message Josh Berkus 2005-01-31 23:13:20 Re: Allow GRANT/REVOKE permissions to be applied to all schema

Browse pgsql-novice by date

  From Date Subject
Next Message Mitch Pirtle 2005-02-01 00:58:42 Re: Last ID Problem
Previous Message Mitch Pirtle 2005-01-31 22:50:33 Re: Last ID Problem