hanze/iwa-panda2

Controller/api/api.php in datatowebsite
Repositories | Summary | Log | Files | README.md

api.php (1857B) download


 1<?php
 2
 3function storeZooData($dataArray): void{
 4    if ($dataArray)
 5    $db = new mysqli("86.92.67.21", "friedel", "hailiwa", "panda");
 6    $query = "INSERT INTO retrieve_zoos (city, wind_chill, date, country) VALUES (?, ?, ?, ?)";
 7    $stmt = mysqli_prepare($db, $query);
 8
 9    foreach ($dataArray as $data) {
10        $city = $data->city;
11        $windchill = $data->windchill;
12        $date = $data->date;
13        $country = $data->country;
14
15        $stmt->bind_param("sdss", $city, $windchill, $date, $country);
16        $stmt->execute();
17    }
18
19    $stmt->close();
20    $db->close();
21}
22
23function storeFacData($dataArray): void{
24    $db = new mysqli("86.92.67.21", "friedel", "hailiwa", "panda");
25    $query = "INSERT INTO retrieve_facilities (city, date_time, humidity) VALUES (?, ?, ?)";
26    $stmt = mysqli_prepare($db, $query);
27
28    foreach ($dataArray as $data) {
29        $city = $data->city;
30        $humidity = $data->humidity;
31        $date_time = $data->date_time;
32
33        $stmt->bind_param("ssd", $city, $date_time, $humidity);
34        $stmt->execute();
35    }
36
37    $stmt->close();
38    $db->close();
39}
40
41$get_windchill = function(&$vars){
42  $token = '3jvl/yb?sRr80s6lTdeOyxV9VTQZkCPRp/bKOWKFWxfL2vhsU4Hhpgcmz9qe0zEk';
43  if(isset($vars['since'])){
44    $since = $vars['since'];
45  }else{
46    $since = "curdate()";
47  }
48  $url = 'http://86.92.67.21/api/windchill/' . $since;
49  $connect = new Model\Connect($url, $token);
50  $response = $connect->connect();
51  storeZooData($response);
52};
53$get_graph = function(&$vars){
54  $token = 'ae9c50dc5cd58c538a0d6aedb17fffedcaffd568d22381dab3ae72baaeb24684';
55  if(isset($vars['since'])){
56    $since = $vars['since'];
57  }else{
58    $since = "curdate()";
59  }
60  $url = 'http://86.92.67.21/api/graph/' . $since;
61  $connect = new Model\Connect($url, $token);
62  $response = $connect->connect();
63  storeFacData($response);
64};