Skip to content

Instantly share code, notes, and snippets.

@BrendonKoz
Created October 23, 2013 21:55
Show Gist options
  • Save BrendonKoz/7127489 to your computer and use it in GitHub Desktop.
Save BrendonKoz/7127489 to your computer and use it in GitHub Desktop.
A way to get the next insert ID if you are certain there won't be any conflicts (other insertions during processing) from MySQL. Source: http://stackoverflow.com/a/12500309/155421
SELECT AUTO_INCREMENT
FROM information_schema.tables
WHERE table_name = 'table_name'
AND table_schema = DATABASE( ) ;
--- or ---
$result = mysql_query("SHOW TABLE STATUS LIKE 'table_name'");
$row = mysql_fetch_array($result);
$nextId = $row['Auto_increment'];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment