如何在php mysqldatabase中获取最后受影响行的id?

时间:2018-04-25 05:36:36

标签: php mysql

我的代码

$query = "select * from others";

但它需要以前的身份证明。当我插入第一行时,它将id值设为0,然后再次插入第二行,它将id值设为1.

1 个答案:

答案 0 :(得分:6)

请使用我的简单代码对您有所帮助

$selectquery="SELECT id FROM tableName ORDER BY id DESC LIMIT 1";
$result = $mysqli->query($selectquery);
$row = $result->fetch_assoc();
echo $row['id'];