c6py0D5G
2017-01-12 03:30:02

<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "dbname";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$xml=simplexml_load_file("external_xml_url") or die("Error: Cannot create object");

foreach ($xml->product as $row) {
$price = $row -> price;

$sql = "INSERT INTO 'table_name' ('price')"
. "VALUES ('$price')";

}

if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?>