如何在代码中获取mysql中的最后一个插入ID?
设置所有变量。
插入有效!
$Restconnection = mysqli_connect("host","user","passwd","db ");
$query3 = mysqli_query($Rconnection, $strSQL3);
答案 0 :(得分:3)
$sql = "INSERT INTO Table_name VALUES(?,?,?)";
if ($Restconnection->query($sql) === TRUE) {
$last_id = $conn->insert_id;
echo "Last inserted ID is: " . $last_id;
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
答案 1 :(得分:2)
print mysqli_insert_id($Restconnection);
答案 2 :(得分:1)
使用mysqli_insert_id($connection)
答案 3 :(得分:1)
使用以下内容:
$last_insert_id = mysqli_insert_id($Restconnection);