How can PHP be used to update a MySQL table with data extracted from an XML file?

To update a MySQL table with data extracted from an XML file using PHP, you can first parse the XML file to extract the necessary data, then establish a connection to the MySQL database and update the table with the extracted data using SQL queries.

<?php
// Load the XML file
$xml = simplexml_load_file('data.xml');

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

// Loop through XML data and update MySQL table
foreach ($xml->data as $data) {
    $id = $data->id;
    $value = $data->value;

    $sql = "UPDATE table_name SET value = '$value' WHERE id = '$id'";
    $mysqli->query($sql);
}

// Close MySQL connection
$mysqli->close();
?>