gpt4 book ai didi

php - 使用 php 在 mysql 中查找最后插入的 ID 的最佳方法

转载 作者:可可西里 更新时间:2023-11-01 06:56:55 26 4
gpt4 key购买 nike

我想知道在 mysql 查询后获取最后插入的 ID 的最佳解决方案是什么?

我找到了以下解决方案:

<?php
function get_current_insert_id($table)
{
$q = "SELECT LAST_INSERT_ID() FROM $table";
return mysql_num_rows(mysql_query($q)) + 1;
}
?>

甚至使用 mysql_insert_id php 函数,但显然这个函数不能很好地与 bigint 一起使用(这就是我在 ID 字段中使用的),如果有很多连续的 sql 查询,它可能不可靠.

有人可以提供可靠且快速的解决方案来完成这项任务吗?

最佳答案

关于php - 使用 php 在 mysql 中查找最后插入的 ID 的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10371306/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com