Re: Re: Getting last record ID created from DB
| From: | Richard Lynch | Date: | Tue, 20 Mar 2007 01:44:18 +0000 |
| Subject: | Re: Re: Getting last record ID created from DB | ||
| References: | 1 2 3 4 5 6 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-250873@lists.php.net to get a copy of this message | ||
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?