title: Get the id of the last inserted mysql row
body: <p>In the database the id for this row is automatically generated. If an INSERT is executed in between the execute in this code and the SELECT I will get the wrong id returned. Is there a better alternative to getting the id and guaranteeing it will be from the row I inserted. I understand that the two statements will happen very close together but I would still like to know if there is a better way of doing this.</p>
  
  <pre><code>my $sthH = $dbh-&gt;prepare("INSERT INTO hardware (cpu_type, cpu_count, memory) VALUES (?,?,?)");
  $resultH = $sthH-&gt;execute($cpu_type, $cpu_count, $memory);
  $hardware_id = $dbh-&gt;selectrow_array("SELECT MAX(hardware_id) FROM hardware;");
  </code></pre>