Guest User

ServerSOAP.php

a guest
Jan 26th, 2017
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.93 KB | None | 0 0
  1. <?php
  2. error_reporting(E_ALL);
  3. ini_set("display_errors", 1);
  4. class ServerSOAP
  5. {
  6.  
  7.   private function getData(){
  8.  
  9.     $uri = 'http://api.nbp.pl/api/exchangerates/rates/c/usd/last/90/?format=json';
  10.     $reqPrefs['http']['method'] = 'GET';
  11.     //$stream_context = stream_context_create($reqPrefs);
  12.    
  13.     //$response = file_get_contents($uri, true, $stream_context);
  14.      $response = file_get_contents($uri);
  15.      print($response);
  16.    
  17.       $data = json_decode($response, true);
  18.    
  19.     if(!$data){
  20.         echo "Error in json-decode";
  21.         exit;
  22.         }
  23.     return $data;
  24.    
  25.   }
  26. //////////////////////////////////////////////////////
  27.   public function setData(){
  28.  
  29.     $table = $this->getData();
  30.     print_r($table);
  31.     var_dump($table);
  32.    
  33.     if(empty($table)){
  34.         echo "table is empty.";
  35.         exit;
  36.         }
  37.    
  38.    
  39.     /* $dbconn = pg_connect("host=localhost port=5432 dbname=dbase user=admin password=admin");
  40.         if(!$dbconn) {
  41.             echo "An error occured. pg_connect\n";
  42.             exit;
  43.         } */
  44.        
  45.        
  46.     foreach($table as $obj){
  47.    
  48.     if(is_array($obj)){
  49.         for($i = 0; $i <= 10; $i++) {
  50.         $obj_no = $obj[$i]['no'];
  51.         $obj_effectiveDate = $obj[$i]['effectiveDate'];
  52.         $obj_bid = $obj[$i]['bid'];
  53.         $obj_ask = $obj[$i]['ask'];
  54.    
  55.         $resultat = pg_query($dbconn, "INSERT INTO public.currency(notowanie,effectivedate,bid,ask)VALUES('".$obj_no."','".$obj_effectiveDate."','".$obj_bid."','".$obj_ask."');");
  56.         }
  57.     }
  58.    
  59.     //var_dump($resultat);
  60.    
  61.         }
  62.    
  63.     while ($row = pg_fetch_assoc($resultat)){
  64.         echo $row['notowanie'];
  65.         }
  66.     pg_close($dbconn);
  67.    
  68.   }
  69.  
  70.   public function buy_currency()
  71.   {
  72.     $dbconn = pg_connect("dbname=dbase user=admin password=admin");
  73.     $result = pg_query($dbconn, "SELECT \"buy_currency\"()");
  74.     $rows = pg_fetch_all($result);
  75.     pg_close($dbconn);
  76.     return $rows;
  77.   }
  78.  
  79.  
  80.  
  81. }
  82.  
  83.  
  84. $options= array('uri'=>'http://localhost:8080/pipd');
  85. $server=new SoapServer(NULL,$options);
  86. $server->setClass('ServerSOAP');
  87. $server->handle();
  88. ?>
Add Comment
Please, Sign In to add comment