in reply to DBI/MySQL and LAST_INSERT_ID()

There is also a dedicated DBI method for this, last_insert_id. The calling parameters are DB dependent, so be sure to check the DBI documentation.

In addition to the caveats mentioned there, one should not wait too long after the insertion to grab the id; the DB handle may still be connected but the id lost. This might be a common problem.

(Just tidying up since this old thread shows up in searches).