title: How can I fetch the last row I inserted using DBI?
body: <p>How can I fetch the last row that was inserted using <a href="http://search.cpan.org/perldoc?DBI" rel="noreferrer">DBI</a> (<a href="http://search.cpan.org/perldoc?DBD::mysql" rel="noreferrer">DBD::mysql</a>)?</p>
  
  <p>Code sample:</p>
  
  <pre><code>my $sth = $dbh-&gt;prepare('INSERT INTO a ( x, y, z ) VALUES ( ?, ?, ? )');
  $sth-&gt;execute( $x, $y, $z );
  </code></pre>
  
  <p>How can I get access to the data that was inserted by the above <code>prepare</code> statement? I need to get the primary ID (<code>AUTOINCREMENT</code>) value.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>From <a href="http://search.cpan.org/perldoc?DBD::mysql" rel="noreferrer">DBD::mysql</a> documentation:</p>
  
  <blockquote>
    <p>An alternative way for accessing this
    attribute is via
    <code>$dbh-&gt;{'mysql_insertid'}</code>.</p>
  </blockquote>
  
  <p>Thank you <a href="https://stackoverflow.com/users/7498/manni">Manni</a> and <a href="https://stackoverflow.com/users/31782/n0rd">n0rd</a> for your answers. :-)</p>