Created
March 25, 2024 18:54
-
-
Save AbhishekGhosh/8b799b29a3171b60b3d0c8978913d0e6 to your computer and use it in GitHub Desktop.
get_data.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$servername = "localhost"; | |
$username = "your_username"; | |
$password = "your_password"; | |
$dbname = "your_database"; | |
// Create connection | |
$conn = new mysqli($servername, $username, $password, $dbname); | |
// Check connection | |
if ($conn->connect_error) { | |
die("Connection failed: " . $conn->connect_error); | |
} | |
// Query to fetch latest water level | |
$sql = "SELECT level FROM water_level ORDER BY id DESC LIMIT 1"; | |
$result = $conn->query($sql); | |
if ($result->num_rows > 0) { | |
// Output data of each row | |
$row = $result->fetch_assoc(); | |
echo $row["level"]; | |
} else { | |
echo "0"; | |
} | |
$conn->close(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment