Skip to content

Instantly share code, notes, and snippets.

@jamesnine
jamesnine / gist:6361514
Created August 28, 2013 02:32
get the last id from a table; both the last known id and last auto_increment value
// next auto increment value
$result = mysql_query("SHOW TABLE STATUS LIKE 'tablename'");
$row = mysql_fetch_array($result);
return $row['Auto_increment'];
// last (highest) id on table
$result = mysql_query("SELECT MAX(id) as lastid FROM `tablename`");
$row = mysql_fetch_assoc($result);
return $row['lastid'];