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

[email protected] (Lester Caine)
Newsgroups php.general
Message-ID <[email protected]>
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.

> Any clues are greatly appreciated..
> I'm looking for the most sql server independent way to do this.

Rene
The 'correct' way of doing this is to use a 'sequence' which is something 
introduced in newer versions of the SQL standard. Firebird(Interbase) has had 
'generators' since the early days (20+ years) and these provide a unique number 
which can then be inserted into the table.

ADOdb emulates sequences in MySQL by creating a separate table for the insert 
value, so you can get the next value and work with it, without any worries. The 
only 'problem' is in situations were an insert is rolled back, a number is lost, 
but that is ACTUALLY the correct result, since there is no way of knowing that a 
previous insert WILL commit when several people are adding records in parallel.

-- 
Lester Caine - G8HFL
-----------------------------
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php
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.