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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, July 20, 2007 1:10 pm, Marcelo Wolfgang wrote:
> 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.

Every DB has a function to handle this.

Use the one appropriate to your DB.

In MySQL, it's:
http://php.net/mysql_insert_id

You're on your own to rtfm and find the others, but never ever try to
roll your own!

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux