<?php
$conn = mysqli_connect("localhost", "root", "", "Exchanges");
$affectedRow = 0;
$xml = simplexml_load_file("https://exhub.io/rates/rates.xml") or die("Error: Cannot create object");
foreach ($xml->children() as $row) {
$from = $row->from;
$to = $row->to;
$in = $row->in;
$out = $row->out;
$minamount = $row->minamount;
$maxamount = $row->maxamount;
$amount = $row->amount;
$sql = "INSERT INTO `Exhub` (`from`,`to`,`in`,`out`,`minamount`,`maxamount`,`amount`) VALUES ('" . $from . "','" . $to . "','" . $in . "','" . $out . "','" . $minamount . "','" . $maxamount . "','" . $amount . "')";
$result = mysqli_query($conn, $sql);
if (! empty($result)) {
$affectedRow ++;
} else {
$error_message = mysqli_error($conn) . "\n";
}
}
?>
<h2>Insert XML Data to MySql Table Output</h2>
<?php
if ($affectedRow > 0) {
$message = $affectedRow . " records inserted";
} else {
$message = "No records inserted";
}
?>
<div class="affected-row">
<?php echo $message; ?>
</div>
<?php if (! empty($error_message)) { ?>
<div class="error-message">
<?php echo nl2br($error_message); ?>
</div>
<?php }
?>
Запись с xml файла работает, а как обновлять эти данные из xml?