request.php (1176B) download
1<?php
2
3$servername = "86.92.67.21";
4$username = "friedel";
5$password = "hailiwa";
6$dbname = "wap2";
7
8$mysqli = mysqli_connect($servername, $username, $password, $dbname);
9
10if (!$mysqli) {
11 die("Connection failed: " . mysqli_connect_error());
12}
13
14
15if (!isset($_SERVER['KEY'])) {
16 http_response_code(400);
17 echo 'Key not provided';
18 exit();
19}
20
21
22
23
24$key = $_SERVER['KEY'];
25
26$keyStatement = "SELECT distinct temperature, wind_speed, dew_point, DATE(date_time) AS date, nl.name as city
27 FROM weather_data wd
28 JOIN station s ON wd.station_name = s.name
29 JOIN contract_station cs ON cs.station_name = s.name
30 JOIN nearestlocation nl ON nl.station_name = s.name
31 JOIN country co ON co.country_code = nl.country_code
32 JOIN geolocation geo ON geo.country_code = co.country_code
33 JOIN contract c ON cs.contract_id = c.contract_id
34 WHERE c.token = ?
35 ORDER BY date DESC, temperature, wind_speed
36 ";
37
38$stmt = $mysqli->prepare($keyStatement);
39$stmt->bind_param("s", $key);
40$stmt->execute();
41$result = $stmt->get_result();
42$row = $result->fetch_all(MYSQLI_ASSOC);
43
44echo json_encode($row);
45
46