Re: Getting auto_increment's next value
| From: | Adam Voigt | Date: | Thu, 15 May 2003 20:49:27 +0000 |
| Subject: | Re: Getting auto_increment's next value | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-147803@lists.php.net to get a copy of this message | ||
http://www.php.net/manual/en/function.mysql-insert-id.php
On Thu, 2003-05-15 at 16:42, Daniel Stark wrote:
> I'm wondering if there is a tutorial on a good way to handle adding new
> records to a mySQL database and getting back the primary key.
> Specifically are people:
>
> 1. inserting the record and then querying for the id based on the add
> values
>
> or
>
> 2. Getting the max(primary_key) and inserting the record with this
> value.
>
> When I search the archive on this subject I saw some examples of the
> second one but none accounted for locking the db to prevent primary key
> hijacking. The first method would seem to suffer in cases where
> identical data exists in the database. While this seems like a good
> place for sub-queries my version of mysql doesn't support them. What is
> the generally accepted method for this?
>
> TIA,
> Dan
>
>
--
Adam Voigt (adam@cryptocomm.com)
Linux/Unix Network Administrator
The Cryptocomm Group