честно я еще не юзал это, просто по аналогии должно быть что то вроде такого
$dbh->last_insert_id()
#last_insert_id
# $rv = $dbh->last_insert_id($catalog, $schema, $table, $field);
# $rv = $dbh->last_insert_id($catalog, $schema, $table, $field, \\%attr);
#Returns a value \'identifying\' the row just inserted, if possible. Typically
#this would be a value assigned by the database server to a column
#with an auto_increment or serial type. Returns undef if the driver
#does not support the method or can\'t determine the value.
и вместо dbh->prepare()
$query->execute();
здесь используется ->do()