Re: Auto-increment value
| From: | Justin French | Date: | Wed, 18 Sep 2002 13:22:05 +0000 |
| Subject: | Re: Auto-increment value | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-116736@lists.php.net to get a copy of this message | ||
I tend to (if I can't use mysql_last_id) insert a unique key into the row,
and pull the row out that matches that key, in order to get the ID...
ensures that it was the right row... then you can delete the unique key.
Justin
on 18/09/02 10:27 PM, Jon Haworth (jhaworth@witanjardine.co.uk) wrote:
> Hi Bob,
>
>> SELECT idno ORDER BY idno DESC LIMIT 1;
>> assuming idno is what gets auto incremented
>
> That's not the best idea - what happens if two users are inserting records
> into the table at nearly-but-not-quite the same time?
>
> 1. Insert A goes through
> 2. Insert B goes through
> 3. LastID A returns the ID of B
> 4. LastID B returns the ID of B
>
> Whoever did insert A would receive the wrong ID.
>
> Cheers
> Jon