$dbh->do("LOCK TABLES tbl WRITE"); $dbh->do("INSERT INTO tbl VALUES(NULL,'foo','bar')"); my $ref = $dbh->selectcol_arrayref(" SELECT LAST_INSERT_ID() FROM tbl"); $dbh->do("UNLOCK TABLES"); #### DATABASE HANDLES The DBD::mysql driver supports the following attributes of database ha +ndles (read only): $infoString = $dbh->{'info'}; $threadId = $dbh->{'thread_id'}; $insertId = $dbh->{'mysql_insertid'} These correspond to mysql_info(), mysql_thread_id() and mysql_insertid +(), respectively. insertid MySQL has the ability to choose unique key values automatically. If th +is happened, the new ID will be stored in this attribute. This attribu +te is not valid for DBD::mSQL. An alternative way for accessing this a +ttribute is via $dbh->{'mysql_insertid'}. (Note we are using the $dbh +in this case!)