„index.php“ hinzufügen
This commit is contained in:
parent
2648343c5f
commit
d893748fa3
|
@ -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)
|
||||
?>
|
Loading…
Reference in New Issue