Perl Monk, Perl Meditation | |
PerlMonks |
Re: Getting last MySQL id with Class::DBIby Phaysis (Pilgrim) |
on May 20, 2003 at 14:02 UTC ( [id://259451]=note: print w/replies, xml ) | Need Help?? |
Or, you could do what I do:
Before I execute the insert query, I put a write lock on the table, perform the insert, and then do a select query for the id of the most recently inserted row (using a column in my table definition of the type timestamp and the clause ORDER BY modified DESC LIMIT 1). I then release the write lock allowing other processes to do their thing. Or, instead of relying on a timestamp column, you could possibly just order by the primary key, descending. This should return the highest key id, which'll possibly be the most-recently inserted row. This 4-step process works well for me, and from what I've gathered it's fairly portable across database engines. -Shawn / (Ph) Phaysis
In Section
Seekers of Perl Wisdom
|
|