MySQL获得指定数据表中auto_increment自增id值的方法及实例

http://kb.cnblogs.com/a/2357592/很多情况下,我们要提前用到当前某个表的auto_increment自增列id,可以通过执行sql语句来查询到这个id值。
show table status where name=’表名’
或者
show table status like ‘表名’

然后从查询到的结果集中获得auto_increment的值

代码实例:<?php mysql_connect("localhost","root",''); mysql_select_db("test"); $sql="show table status where name='members'"; $query=mysql_query($sql); $res=mysql_fetch_array($query); echo "当前表的自增id为:".$res['Auto_increment']; ?>

posted @ 2014-11-09 09:27  程序员斯文  阅读(736)  评论(0编辑  收藏  举报