What is the equivalent function to mysql_insert_id() in MySQL for retrieving the last inserted ID in PHP?

When inserting a new record into a MySQL database using PHP, you may need to retrieve the ID of the last inserted record. The equivalent function to mysql_insert_id() in MySQL for retrieving the last inserted ID in PHP is mysqli_insert_id(). This function returns the ID generated by an AUTO_INCREMENT column in the previous INSERT query.

// Connect to MySQL database
$mysqli = new mysqli("localhost", "username", "password", "database");

// Insert a new record into a table
$mysqli->query("INSERT INTO table_name (column1, column2) VALUES ('value1', 'value2')");

// Get the ID of the last inserted record
$last_insert_id = $mysqli->insert_id;

// Use the last inserted ID as needed
echo "Last inserted ID: " . $last_insert_id;