如何获取最后插入的ID? [英] How to get the last inserted ID?
本文介绍了如何获取最后插入的ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图从 PHP 中的 MySQL 数据库中获取最后插入的 ID,我想知道最好的方法是什么?
I am trying to fetch the last inserted ID from MySQL database in PHP and I was wondering what would be the best way to do it?
我目前正在使用这种解决方案,但必须有更好更安全的方法.那么有人可以帮助我吗?谢谢
I am currently using this kind of solution, but there has to be a better and safer way. So would someone please help me? Thanks
Some insert statement...
$query = "SELECT MAX(aid) FROM asset";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$pickassssult= $row['MAX(aid)'];
}
推荐答案
PHP 有一个函数叫做:
PHP has a function called:
mysql_insert_id();
更多信息http://lt.php.net/manual/en/function.mysql-插入-id.php
这篇关于如何获取最后插入的ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文