Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. <?php
  2.  
  3. $dblocation = "localhost";
  4. $dbuser = "root";
  5. $dbpassword = "larinlox";
  6.  
  7. $connector = new PDO("mysql:host=localhost;dbname=exchange_rates", $dbuser, $dbpassword);
  8.  
  9. $query = "SELECT * FROM Exchange_rts WHERE date_update = \"".date("m.d.y")."\";";
  10. $result = $connector->query($query);
  11.  
  12.  
  13. $fetch = $result->fetchAll(PDO::FETCH_OBJ);
  14.  
  15. if($result->rowCount() > 0) {
  16. foreach ($fetch as $row){
  17. foreach ($row as $key => $val){
  18. print "<td>$key $val</td>";
  19. }
  20. print "</br>\n";
  21. }
  22. } else {
  23. $url = "http://www.cbr.ru/scripts/XML_daily.asp?date_req=".date("m.d.Y");
  24. $source = file_get_contents($url);
  25. $ValCurs = new SimpleXMLElement($source);
  26.  
  27. foreach ($ValCurs->Valute as $val) {
  28. $add_query = "INSERT INTO `Exchange_rts` (`id`, `values_money`, `date_update`) VALUES($val->NumCode,$val->Value,\"".date("m.d.Y")."\"";
  29. $connector->query($add_query);
  30. }
  31. }
  32. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement