-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest2.php
34 lines (28 loc) · 953 Bytes
/
test2.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
$servername = "mysql.agh.edu.pl:3306";
$username = "rojowska";
$password = "pass";
$dbname = "rojowska";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT medicine, dose, time_of_day, reading_time FROM Medicines ORDER BY id DESC";
if ($result = $conn->query($sql)) {
$response["Medicines"] = array();
while ($row = $result->fetch_assoc()) {
$product = array();
$product["medicine"] = $row["medicine"];
$product["dose"] = $row["dose"];
$product["time_of_day"] = $row["time_of_day"];
$product["reading_time"] = $row["reading_time"];
array_push($response["Medicines"], $product);
}
$response["success"] = 1;
echo json_encode($response);
} else {
$response["success"] = 0;
$response["message"] = "No products found";
echo json_encode($response);
}
?>