commit fad453ab019313c1999581365033fbd551cb0b8d
parent 8390f7a11bee3cc6d798414471a0d3b89ac1fc0a
Author: LennartSchroot <[email protected]>
Date: Wed, 28 Jun 2023 16:19:24 +0200
windchill naar panda database
Diffstat:
3 files changed, 48 insertions(+), 15 deletions(-)
diff --git a/Controller/api/api.php b/Controller/api/api.php
@@ -1,10 +1,31 @@
<?php
+
+function storeData($dataArray): void{
+ $db = new mysqli("86.92.67.21", "friedel", "hailiwa", "panda");
+ $query = "INSERT INTO retrieve_zoos (city, wind_chill, date) VALUES (?, ?, ?)";
+ $stmt = mysqli_prepare($db, $query);
+
+ foreach ($dataArray as $data) {
+ $city = $data->city;
+ $windchill = $data->windchill;
+ $date = $data->date;
+
+ $stmt->bind_param("sdss", $city, $windchill, $date);
+ $stmt->execute();
+ }
+
+ $stmt->close();
+ $db->close();
+}
+
$test = function(&$vars){
$token = '3jvl/yb?sRr80s6lTdeOyxV9VTQZkCPRp/bKOWKFWxfL2vhsU4Hhpgcmz9qe0zEk';
$url = 'http://86.92.67.21/api/windchill';
$connect = new Model\Connect($url, $token);
$response = $connect->connect();
+ var_dump($response);
foreach($response as $obj){
echo "city " . $obj->city . " windchill corrected:" . $obj->windchill . "<br>";
}
+ storeData($response);
};
\ No newline at end of file
diff --git a/Controller/storeData/storeData.php b/Controller/storeData/storeData.php
@@ -0,0 +1,20 @@
+<?php
+//function storeData($dataArray): void
+//{
+// $db = new mysqli("86.92.67.21", "friedel", "hailiwa", "panda");
+// $query = "INSERT INTO retrieve_zoos (city, wind_chill, date) VALUES (?, ?, ?)";
+// $stmt = mysqli_prepare($db, $query);
+//
+// foreach ($dataArray as $data) {
+// $city = $data->city;
+// $windchill = $data->windchill;
+// $date = $data->date;
+//
+// $stmt->bind_param("sis", $city, $windchill, $date);
+// $stmt->execute();
+// }
+//
+// $stmt->close();
+// $db->close();
+//}
+?>
diff --git a/Model/Key.php b/Model/Key.php
@@ -17,21 +17,13 @@ class Key
}
}
- function retrieveZooData($key)
- {
- $db = new mysqli("86.92.67.21", "friedel", "hailiwa", "wap2");
+ function retrieveZooData($key){
+ $db = new mysqli("86.92.67.21", "friedel", "hailiwa", "panda");
$weather_data = [];
- $query = "SELECT distinct temperature, wind_speed, nl.name as city, co.country as country
- FROM weather_data wd
- JOIN station s ON wd.station_name = s.name
- JOIN contract_station cs ON cs.station_name = s.name
- JOIN nearestlocation nl ON nl.station_name = s.name
- JOIN country co ON co.country_code = nl.country_code
- JOIN geolocation geo ON geo.country_code = co.country_code
- JOIN contract c ON cs.contract_id = c.contract_id
- WHERE c.token = '3jvl/yb?sRr80s6lTdeOyxV9VTQZkCPRp/bKOWKFWxfL2vhsU4Hhpgcmz9qe0zEk'
- AND date(wd.date_time) = date(curdate())
- GROUP BY nl.name
+ $query = "SELECT distinct windchill, city, date
+ FROM retrieve_zoos
+ AND date = curdate()
+ GROUP BY city
";
$stmt = mysqli_prepare($db, $query);
@@ -43,7 +35,7 @@ class Key
$weather_data[] = [
'windchill' => $wind_chill,
'location' => $row['city'],
- 'country' => $row['country']
+// 'country' => $row['country']
];
}
header('Content-Type: application/json');