Knowledgebase:MySQLi
Fungsi mysqli_insert_id()
Posted by Ari Sigit on 10 June 2019 12:59 pm
Definisi dan Penggunaan
Fungsi mysqli_insert_id () mengembalikan id (dihasilkan dengan AUTO_INCREMENT) yang digunakan dalam permintaan terakhir.
Contoh Script:
<?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);
?>