Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $dblocation = "localhost";
- $dbuser = "root";
- $dbpassword = "larinlox";
- $connector = new PDO("mysql:host=localhost;dbname=exchange_rates", $dbuser, $dbpassword);
- $query = "SELECT * FROM Exchange_rts WHERE date_update = \"".date("m.d.y")."\";";
- $result = $connector->query($query);
- $fetch = $result->fetchAll(PDO::FETCH_OBJ);
- if($result->rowCount() > 0) {
- foreach ($fetch as $row){
- foreach ($row as $key => $val){
- print "<td>$key $val</td>";
- }
- print "</br>\n";
- }
- } else {
- $url = "http://www.cbr.ru/scripts/XML_daily.asp?date_req=".date("m.d.Y");
- $source = file_get_contents($url);
- $ValCurs = new SimpleXMLElement($source);
- foreach ($ValCurs->Valute as $val) {
- $add_query = "INSERT INTO `Exchange_rts` (`id`, `values_money`, `date_update`) VALUES($val->NumCode,$val->Value,\"".date("m.d.Y")."\"";
- $connector->query($add_query);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement