Hi there I am trying to pull XML data from this website (rates.fxcm.com/RatesXML3) and then I was going to put it into an MySQL database. First, the cURL functions are being used to pull this data,
$url ="http://rates.fxcm.com/RatesXML3";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$data = curl_exec($ch);
curl_close($ch);
then SimpleXML parses the data into what I believe is an array of some form:
$xml = new SimpleXmlElement($data, LIBXML_NOCDATA);
and
foreach ($xml -> Rate as $rowx){
$Symbol = (string)$rowx -> Symbol;
$Bid = (real)$rowx -> Bid;
$Ask = (real)$rowx -> Ask;
$Direction = (int)$rowx -> Direction;
It works up until this point, as when I echo the results, I get the 1st rows 4 columns, then the 2nd rows 4 columns, then the 3rd etc. right the way down to the last record on the site.
However, whenever I try to write this data to my MySQL table, i get 63 "MySQL Error" messages echo'd to me. My possible thoughts are that I've parsed it wrong, my host doesn't allow certain things (Although I can write data to databases with other PHP scripts), or I've structured it wrong.
Here is the full code, thanks to anyone who helps :) :
<?php
$url ="http://rates.fxcm.com/RatesXML3";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$data = curl_exec($ch);
curl_close($ch);
$xml = new SimpleXmlElement($data, LIBXML_NOCDATA);
$con = mysqli_connect("localhost","Username","Password","Database") or die(mysqli_error($con));
foreach ($xml -> Rate as $rowx){
$Symbol = (string)$rowx -> Symbol;
$Bid = (real)$rowx -> Bid;
$Ask = (real)$rowx -> Ask;
$Direction = (int)$rowx -> Direction;
$sql = "INSERT INTO 'FXCM_Rates' ('Symbol', 'Bid', 'Ask', 'Direction') VALUES ('$Symbol', '$Bid', '$Ask', '$Direction')";
$result = mysqli_query($con,$sql);
if (!$result) {
echo 'MySQL ERROR';
} else{
echo 'SUCCESS';
}
}
?>