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

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 (view raw or flat)
Thread:
Lists: pgsql-hackerspgsql-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

pgsql-novice by date

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

pgsql-hackers by date

Next:From: Mitch PirtleDate: 2005-02-01 00:58:42
Subject: Re: Last ID Problem
Previous:From: Josh BerkusDate: 2005-01-31 23:13:20
Subject: Re: Allow GRANT/REVOKE permissions to be applied to all schema

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