Skip to content

Instantly share code, notes, and snippets.

### Keybase proof
I hereby claim:
* I am jamesnine on github.
* I am jamesnine (https://keybase.io/jamesnine) on keybase.
* I have a public key whose fingerprint is 1AF1 B429 1122 ED58 A043 2A84 BE6F D4E2 EEE5 EDA5
To claim this, I am signing this object:
@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'];