How can XML file contents be efficiently imported into a MARIA DB using PHP?

To efficiently import XML file contents into a MARIA DB using PHP, you can use the SimpleXML extension in PHP to parse the XML file and then insert the data into the database using SQL queries. This can be achieved by looping through the XML data and inserting each record into the database.

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

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

// Loop through the XML data and insert into the database
foreach ($xml->record as $record) {
    $name = $record->name;
    $age = $record->age;
    
    $query = "INSERT INTO table_name (name, age) VALUES ('$name', '$age')";
    $mysqli->query($query);
}

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