[thelist] Sessions in PHP4
Liz Lawson
lizlawson at charitycards.co.uk
Wed Jul 26 03:31:41 CDT 2000
>> ... mysql offers a LAST_INSERT_ID function (as in SELECT
>> LAST_INSERT_ID FROM table_whatever), which returns the
>> last value automatically generated for an AUTO_INCREMENT
>> field, so you could retrieve the primary key for the first insert that
>way.
......snip........
>on the other hand, i wonder if it's all that efficient, i mean, it's
>[almost] the same as select max(id)
>
nope....LAST_INSERT_ID gets the last ID inserted by the thread that calls
it, while select max(id)
gets the maxium value, which means that if thread B did an insert between
thread A inserting and getting the
max(id), thread A would have the wrong ID....remember, mysql doesn't have
(production-safe) transactions, so
without LAST_INSERT_ID you'd have to explicitly lock the table to ensure you
got the correct Id back.
Liz
More information about the thelist
mailing list