如何使用php在mysql中生成下一个自动递增编号? [英] How to generate next auto increment number in mysql using php?

查看:80
本文介绍了如何使用php在mysql中生成下一个自动递增编号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用php在mysql中获取下一个自动递增编号.我这样尝试过:

I was trying to fetch next auto increment number in mysql using php. I tried this way:

<?
$q=mysql_query("SELECT * FROM `users`");
$next_auto_inc=mysql_num_rows($q)+1;
?>

但是,当删除任何行时,此操作不起作用.我希望你明白我的意思.如何使用php来做到这一点?

But, this when any row is deleted don't work. I hope you got what I mean. How can I do this using php?

推荐答案

您不能这样做来获取表数据.您必须获取表状态才能使用php获取自动递增编号.而且,您可以执行以下操作:

You can't do that fetching the table data. You have to fetch the table status to get the auto increment number using php. And that, you can do something like this:

$q = mysql_query("SHOW TABLE STATUS LIKE 'test'");
$row = mysql_fetch_assoc($q);
$next_increment = $row['Auto_increment'];
echo "next increment number: [$next_increment]";

希望这会有所帮助:)

[来源 ]

这篇关于如何使用php在mysql中生成下一个自动递增编号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆