n = mysql::InsertId(dbh)
Returns the ID generated for an AUTO_INCREMENT column by the previous query. Use this function after you have performed an INSERT query into a table that contains an AUTO_INCREMENT field.
Note that mysql::InsertId() returns 0 if the previous query does not generate an AUTO_INCREMENTvalue. If you need to save the value for later, be sure to call mysql::InsertId() immediately after the query that generates the value.
Also note that the value of the SQL LAST_INSERT_ID() function always contains the most recently generated AUTO_INCREMENT value, and is not reset between queries because the value of that function is maintained in the server.