获取下一个自动增量
我知道这并不复杂,但我不记得该怎么做。
我只需要知道下一个自动增量。
$result = mysql_query("
SHOW TABLE STATUS LIKE Media
");
$data = mysql_fetch_assoc($result);
$next_increment = $data['Auto_increment'];
...但我不会为我工作,我做错了什么?
I know this isn't so complicated but I can't remember how to do.
I just need to know the next auto increment.
$result = mysql_query("
SHOW TABLE STATUS LIKE Media
");
$data = mysql_fetch_assoc($result);
$next_increment = $data['Auto_increment'];
...but i won't work for me, what am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
表的名称需要用单引号引起来,如下所示:
'table_name'
所以现在工作得很好。
:)
The name of the table needed to be wrapped with single quotes like this:
'table_name'
So it works just fine now.
:)
查询应如下所示:
The query should look like this:
另一种方法,但速度较慢,是:
information_schema 对于从许多方案获取数据最有用。
Another way, but slow, is:
The information_schema is mostly usefull for getting data from many schemes.
您也可以使用这个功能
You can also use this function
如果您需要知道下一个 auto_increment,那么 99% 的可能性是您做错了。您应该只执行即将执行的插入操作,而不是获取下一个 auto_increment,然后使用 SELECT LAST_INSERT_ID() 从该插入中获取 auto_increment 值。
如果您尝试猜测下一个 auto_increment 值并且有多个用户同时执行此操作,您经常会得到错误的值。
if you need to know the next auto_increment, then it's 99% likely you're doing it wrong. instead of the getting the next auto_increment, you should just do the insert you're about to do, then use
SELECT LAST_INSERT_ID()
to get the auto_increment value from that insert.if you try to guess the next auto_increment value and you have multiple users doing it at the same time, you'll frequently get the wrong value.