At 2:44 PM -0600 2000-04-10, Derick Siddoway wrote:
>Paul DuBois <paul@stripped> wrote:
>> At 11:47 AM -0300 04-10-2000, cristiano@stripped wrote:
>> > Hi all,
>> >
>> > I use this function:
>> >
>> > mysql_insert_id()
>> >
>> > My problem is:
>> >
>> > If I had two or more INSERT`s in same time, what this function return?
>> >
>> > PS: I had a AUTO_INCREMENT column.
>> >
>> > Regards,
>> >
>> > Cristiano
>>
>> I assume you are wondering what happens if two different clients
>> insert a row into the table at the same time?
>>
>> Answer: each client will get back the ID generated for the row
>> it inserted; they will not interfere with each other, because
>> mysql_insert_id() returns a client-specific value.
>
>I think Christiano's asking a different question. I read it as,
>if I use a multi-row insert (something like INSERT INTO table
>VALUES(0,1),(0,2); ), what value is returned by mysql_insert_id()?
>
>I don't think that this behavior is defined, but my reading
>of the source may be suspect.
Assuming the rows are inserted into the table in the same order
that they are listed in the INSERT statement, I would think that
mysql_insert_id() would return the AUTO_INCREMENT value generated
for the final row. That's just a guess.
Actually, now that I think about it a bit more, you don't even
have to assume anything about the order in which the rows are
inserted into the table, because the same number of AUTO_INCREMENT
values will be generated now matter which order the rows are
inserted. And in any case, mysql_insert_id() will return the final
value that was generated.
--
Paul DuBois, paul@stripped