Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting a bank rss feed into my mysql database with php?
    primarykey
    data
    text
    <p>I need some help getting a bank rss feed into my database. I've tried a few things but I just can't seem to get it to work.</p> <p>The rss feed is from <a href="http://www.bankofcanada.ca/stats/assets/rates_rss/noon/en_all.xml" rel="nofollow">http://www.bankofcanada.ca/stats/assets/rates_rss/noon/en_all.xml</a></p> <pre><code>&lt;?php //Find and grab needed libraries and files. require_once('proxy_bypass.php'); require_once ('config.php'); $url = $BOCRSS; // Bank of Canada RSS. $rss = @simplexml_load_string(get_file($url)); // Get the rss feed data. if($rss) { foreach($rss-&gt;item as $entry) { //For each RSS item in the rss xml file. $cb = $entry-&gt;children('http://www.cbwiki.net/wiki/index.php/Specification_1.1'); //var_dump($cb); //die(); $code = $entry[targetCurrency]; $curr = $entry[value]; //echo $curr .' '. $code . '&lt;br/&gt;'; //Can be deleted - prints out data. $dbc = mysql_connect($db_host,$db_user,$db_password); //Connect to Shares. mysql_select_db($db_name, $dbc); //Select database. $qry = "INSERT INTO $db_table (currencycode,rate) VALUES ('$code', '$curr')"; //Creates the query. if (!$dbc){ die('Could not connect: ' . mysql_error()); // Echo this is the connection to the database can't be made. } if (mysql_query($qry, $dbc)) { echo "Database created"; // Echo this if the RSS feed in placed in the database. } else { echo "Error creating database: " . mysql_error(); //Otherwise say this. } mysql_close($dbc); // Close the database connection. } } else echo "Error with RSS feed"; //Echo error if RSS is unreachable. ?&gt; </code></pre> <p>The two files I have included get me through my university's proxy server and the config holds my mysql database details and urls for the rss feed.</p> <p>The var dump gives me this:</p> <p><em>object(SimpleXMLElement)#63 (1) { ["statistics"]=> object(SimpleXMLElement)#65 (2) { ["country"]=> string(2) "CA" ["exchangeRate"]=> object(SimpleXMLElement)#66 (5) { ["value"]=> string(6) "1.0029" ["baseCurrency"]=> string(3) "CAD" ["targetCurrency"]=> string(3) "USD" ["rateType"]=> string(24) "Bank of Canada noon rate" ["observationPeriod"]=> string(25) "2012-02-01T12:15:00-05:00" } } }</em> </p> <p>Now I'm a beginner to PHP so it's probably all wrong. I'm trying to get the 'targetCurrency' and 'value' into my database but all I get is 50+ empty rows. It must mean that the database is being generated but nothing is going in. If anyone can change the code to get it to work, I would be greatly appreciated as I've tried to get it to work but to no avail.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload