mysql获取一个表中的下一个自增(id)值的方法
MySQL: Get next AUTO_INCREMENT value from/for table
Note to self: To get the next auto_increment value from a table run this query: SELECT AUTO_INCREMENT FROM information_schema.TABLES WHERE TABLE_SCHEMA = $dbName AND TABLE_NAME = $tblName. Don’t forget it (again).
给自己做笔记:从表中获取下一个自增值时只要运行以下sql语句即可:
AUTO_INCREMENT FROM information_schema.TABLES WHERE TABLE_SCHEMA = $dbName AND TABLE_NAME = $tblName;
例如:
SELECT auto_increment FROM information_schema.`TABLES` WHERE TABLE_SCHEMA=’my_db_name’ AND TABLE_NAME=’my_table_name’;
原文地址:http://www.bram.us/2008/07/30/mysql-get-next-auto_increment-value-fromfor-table/
另附一种PHP+mysql的方法:
$tablename = “tablename”;
$next_increment = 0;
$qShowStatus = “SHOW TABLE STATUS LIKE ‘$tablename’”;
$qShowStatusResult = mysql_query($qShowStatus) or die ( “Query failed: ” . mysql_error() . “<br/>” . $qShowStatus );
$row = mysql_fetch_assoc($qShowStatusResult);
$next_increment = $row['Auto_increment'];
echo “next increment number: [$next_increment]“;
?>