Re: [PHP] SQL insert () values (),(),(); how to get auto_increments properly?

[email protected] (tedd)
Newsgroups php.general
Message-ID <p06240816c79c646f2238@[192.168.1.102]>
At 7:07 AM +0100 2/13/10, Rene Veerman wrote:
>Hi.
>
>I'm looking for the most efficient way to insert several records and
>retrieve the auto_increment values for the inserted rows, while
>avoiding crippling concurrency problems caused by multiple php threads
>doing this on the same table at potentially the same time.
>
>-snip-
>
>Any clues are greatly appreciated..
>I'm looking for the most sql server independent way to do this.

Rene:

I'm not sure what would be the most efficient way to solve the race 
problems presented here, but you might want to not confront the race 
problem at all and solve this a bit more straight forward -- for 
example:

Three steps for each record:

1. Generate a unique value (i.e., date/time).
2. Insert the record with the unique value in a field and the 
auto_increment ID will be automatically created.
3. Then search for the record with that unique value and retrieve the 
auto_incremented ID value.

While this might take a few more cycles, it would work.

If you want your auto_increment ID's to be in sequence, then that's a 
different problem and if so, maybe you should rethink the problem. 
I've never seen a problem where the ID's were required to be anything 
other than unique.

Cheers,

tedd

-- 
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.