Re: best technique to get the ID of the last inserted value

From: Date: Fri, 20 Jul 2007 18:49:56 +0000
Subject: Re: best technique to get the ID of the last inserted value
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-259223@lists.php.net to get a copy of this message
One easy solution would be to get the ID before you do the insert.... i.e. in Oracle you would run the query: select some_id_generating_seq.nextval from dual and then you would use that id to insert and you would know the id after that...and the DB would take care of locking and such. So, check the help pages for your DB of choice to see what support they have for something like that. -B Marcelo Wolfgang wrote:
Hi all, I'm a newbie in PHP, and I want to know what's the best technique you guys use when you need to get the id of the last inserted value in the database. My first thought is to do a SELECT on the db and get the last id, but I know that if I have two almost simultaneous connections I may get the wrong one, so that's the why of my question. TIA Marcelo Wolfgang


« previous php.general (#259223) next »