What is the function in PHP that can be used to retrieve the ID of the last inserted record in a MySQL database?

To retrieve the ID of the last inserted record in a MySQL database using PHP, you can use the mysqli_insert_id() function. This function returns the auto-generated ID that was created by the last INSERT query. After executing an INSERT query, you can call mysqli_insert_id() to get the ID of the newly inserted record.

// Assuming $conn is your mysqli database connection object

// Perform your INSERT query here

$last_insert_id = mysqli_insert_id($conn);

// $last_insert_id now contains the ID of the last inserted record