in reply to Getting last MySQL id with Class::DBI
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
If idle hands are the tools of the devil, are idol tools the hands of god?
|
|---|