PHP mysqli_insert_id()函数
此代码打印w3school.com中的最后一个ID:
<?php
$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysqli_query($con,"INSERT INTO Persons (FirstName,LastName,Age)
VALUES ('Glenn','Quagmire',33)");
// Print auto-generated id
echo "New record has id: " . mysqli_insert_id($con);
mysqli_close($con);
?>
但我不想插入任何内容......我只是想拥有最后一个ID,
我尝试构建我自己的函数:
function getlast()
{
$con = connectDB();
$sql = "SELECT id FROM Articls";
$result = $con->query($sql);
$latestID = $result->insert_id;
disconnectDB($con);
return $latestID;
}
但似乎错了