我似乎无法找到这个。也许我问的是错误的问题。我的数据库中的第一个字段是一个ID,其中INT设置为自动递增。当我创建一个新条目时,我想获取创建的id,但我不知道如何。
$query = mysqli_query($myConnection, "INSERT INTO books (title, author, description)
VALUES('$title','$author','$description')")
or die (mysqli_error($myConnection));
echo 'Operation Completed Successfully! <br /><br /><a href="index.php">Click Here</a><br /><br />';
//HERE I WOULD ALSO LIKE TO ECHO THE ID THAT WAS CREATE WITH AUTO INCREMENT
echo $title . "<br />" . $author . "<br /> . $description;
答案 0 :(得分:7)
试试这个:
echo "The last id was: " . msqli_last_insert_id();
答案 1 :(得分:3)
使用此功能:mysqli_insert_id()