Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting(E_ALL);
- ini_set("display_errors", 1);
- class ServerSOAP
- {
- private function getData(){
- $uri = 'http://api.nbp.pl/api/exchangerates/rates/c/usd/last/90/?format=json';
- $reqPrefs['http']['method'] = 'GET';
- //$stream_context = stream_context_create($reqPrefs);
- //$response = file_get_contents($uri, true, $stream_context);
- $response = file_get_contents($uri);
- print($response);
- $data = json_decode($response, true);
- if(!$data){
- echo "Error in json-decode";
- exit;
- }
- return $data;
- }
- //////////////////////////////////////////////////////
- public function setData(){
- $table = $this->getData();
- print_r($table);
- var_dump($table);
- if(empty($table)){
- echo "table is empty.";
- exit;
- }
- /* $dbconn = pg_connect("host=localhost port=5432 dbname=dbase user=admin password=admin");
- if(!$dbconn) {
- echo "An error occured. pg_connect\n";
- exit;
- } */
- foreach($table as $obj){
- if(is_array($obj)){
- for($i = 0; $i <= 10; $i++) {
- $obj_no = $obj[$i]['no'];
- $obj_effectiveDate = $obj[$i]['effectiveDate'];
- $obj_bid = $obj[$i]['bid'];
- $obj_ask = $obj[$i]['ask'];
- $resultat = pg_query($dbconn, "INSERT INTO public.currency(notowanie,effectivedate,bid,ask)VALUES('".$obj_no."','".$obj_effectiveDate."','".$obj_bid."','".$obj_ask."');");
- }
- }
- //var_dump($resultat);
- }
- while ($row = pg_fetch_assoc($resultat)){
- echo $row['notowanie'];
- }
- pg_close($dbconn);
- }
- public function buy_currency()
- {
- $dbconn = pg_connect("dbname=dbase user=admin password=admin");
- $result = pg_query($dbconn, "SELECT \"buy_currency\"()");
- $rows = pg_fetch_all($result);
- pg_close($dbconn);
- return $rows;
- }
- }
- $options= array('uri'=>'http://localhost:8080/pipd');
- $server=new SoapServer(NULL,$options);
- $server->setClass('ServerSOAP');
- $server->handle();
- ?>
Add Comment
Please, Sign In to add comment