1
0
Fork 0

„index.php“ hinzufügen

This commit is contained in:
Manuel Kamper 2023-05-29 07:09:08 +00:00
parent 2648343c5f
commit d893748fa3
1 changed files with 26 additions and 0 deletions

26
index.php Normal file
View File

@ -0,0 +1,26 @@
<?php
$servername = "sql-server-host";
$username = "solar";
$password = "password";
$dbname = "solar";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
$jsonres = array("Error"=>$conn->connect_error);
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM solardata ORDER BY id DESC LIMIT 1";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$jsonres = array("today"=>$row["today"], "month"=>$row["month"], "year"=>$row["year"], "lifetime"=>$row["lifetimt"], "current"=>$row["current"], "last_update"=>$row["last_update"]);
}
} else {
$jsonres = array("Error"=>"No result from database.");
}
$conn->close();
echo json_encode($jsonres)
?>