title: Perl and MySQL - Return a field from last row of a table using DBI possibly with last_insert_id?
body: <p>I am trying to return a members <code>firstname</code> field from the table <code>users</code> from the last row of <code>users</code>.</p>
  
  <pre><code> my $dbh = DBI-&gt;connect($dsn, $db_user_name, $db_password) or die "$DBI::errstr";
      my $LastID = $dbh-&gt;last_insert_id(`firstname`); ##but I want from table users
      print qq~$LastID~;
  </code></pre>
  
  <p>This error is returned from above:</p>
  
  <pre><code>DBI last_insert_id: invalid number of arguments: got handle + 0, expected handle + between 4 and 5
  Usage:    $h-&gt;last_insert_id($catalog, $schema, $table_name, $field_name [, \%attr ])
  </code></pre>
  
  <p>So, what would be the "best" way (best being best for server, fastest, least memory, load, least amount of overhead.. whatever) to get the field <code>firstname</code> from the last row in the table <code>users</code>?</p>
  
  <p>Realize my example above is not to be taken seriously as I have no idea how to do this without just doing something like my crude, but functional: 
  (p.s.  UserID is NOT assigned by auto increment but, is in numeric order and a new user gets a higher UserID. Just the way this was when I tackled the pre existing problem.)</p>
  
  <pre><code>my $dbh = DBI-&gt;connect($dsn, $db_user_name, $db_password) or die "$DBI::errstr";
  my $dsn = $dbh-&gt;prepare(qq{SELECT `firstname` FROM `users` ORDER BY ABS(UserID) DESC LIMIT ?,?});
  $dsn-&gt;execute('1','1') or die "$DBI::errstr";
  while(@nrow = $dsn-&gt;fetchrow_array()) {
  $firstname = $nrow[0];
  }
  </code></pre>
  
  <p>I assumed since I was using DBI that may provide the best solution but, I am inexperienced obviously and need some advice and guidance to learn the proper way to do this. Thanks for any assistance.</p>