Is there a specific function in PHP that simplifies the process of retrieving the last inserted ID?

When inserting data into a database using PHP, it is common to retrieve the last inserted ID for further processing or referencing. One way to simplify this process is by using the `mysqli_insert_id()` function in PHP, which retrieves the ID generated by a query on a connection to a MySQL database.

// Establish a connection to the database
$conn = new mysqli($servername, $username, $password, $dbname);

// Check the connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Insert data into the database
$sql = "INSERT INTO table_name (column1, column2) VALUES ('value1', 'value2')";
$conn->query($sql);

// Retrieve the last inserted ID
$last_id = $conn->insert_id;

// Close the connection
$conn->close();

// Use the last inserted ID for further processing
echo "Last inserted ID is: " . $last_id;