What function in PHP can be used to retrieve the last auto_increment ID inserted into a MySQL database?
To retrieve the last auto_increment ID inserted into a MySQL database in PHP, you can use the mysqli_insert_id() function. This function returns the ID generated by a query on a table with an AUTO_INCREMENT column. After inserting a new row into a table with an auto_increment column, you can call this function to get the last inserted ID.
// Connect to MySQL database
$connection = mysqli_connect("localhost", "username", "password", "database");
// Insert a new row into a table with an auto_increment column
mysqli_query($connection, "INSERT INTO table_name (column1, column2) VALUES ('value1', 'value2')");
// Get the last auto_increment ID inserted
$last_id = mysqli_insert_id($connection);
// Output the last inserted ID
echo "Last inserted ID: " . $last_id;
// Close the database connection
mysqli_close($connection);