Re: Re: Getting last record ID created from DB

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

 



On Sat, March 17, 2007 11:19 am, Mark wrote:
> insert into the_table (..., email,..);
> select user_id from the_table where email = '...';
>
> Is probably the best way given the nature of the table and skill level
> of
> the developer asking the question.

$query = "insert into the_table(...)";
mysql_query($query);
$user_id = mysql_insert_id();

If you are writing a PHP/MySQL web application, and your skill level
is not up to typing that last line of code above, stop writing a
PHP/MySQL web application and go do something else.

Something that requires no skill whatsoever. :-)

Even if you just plain don't "get" what the concurrency problem is,
you can STILL follow the basic instruction of "do this":

$user_id = mysql_insert_id();

right after the INSERT is done, and you will get your auto_increment
ID back.

Anything else you try to do is just a time bomb ticking away.

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving 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