PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
-- Hint: use Ctrl+Enter for SQL autocomplete create table `Exhub` ( `from` varchar(24), `to` varchar(24), `in` double, `out` double, `minamount` double, `maxamount` double, `amount` double, primary key `from_to` (`from`, `to`) );
Copy Clear
Copy Format Clear
<?php $affectedRow = 0; $xml = simplexml_load_file("https://exhub.io/rates/rates.xml") or die("Error: Cannot create object"); $stmt = $mysqli->prepare("INSERT INTO `Exhub` ( `from`,`to`,`in`,`out`,`minamount`,`maxamount`,`amount` ) VALUES (?,?,?,?,?,?,?) ON DUPLICATE KEY UPDATE `in` = ?, `out` = ?, `minamount` = ?, `maxamount` = ?, `amount` = ?;" ); 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; $stmt->bind_param('ssdddddddddd', $from, $to, $in, $out, $minamount, $maxamount, $amount, $in, $out, $minamount, $maxamount, $amount ); $stmt->execute(); if ($stmt->affected_rows > 0) { $affectedRow ++; } else { $error_message = mysqli_error($mysqli) . "\n"; } } ?> <h2>Insert XML Data to MySql Table Output</h2> <?php if ($affectedRow > 0) { $message = $affectedRow . " records inserted"; } else { $message = "No records inserted"; } echo $message; ?>
Show:  
Copy Clear