-
Notifications
You must be signed in to change notification settings - Fork 4
/
dbread.php
59 lines (32 loc) · 1.33 KB
/
dbread.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Code Written by Rishi Tiwari
// Website:- https://tricksumo.com
// Reference:- https://www.w3schools.com/php/php_mysql_select.asp
//
//
<?php
$host = "localhost"; // host = localhost because database hosted on the same server where PHP files are hosted
$dbname = "sumodb"; // Database name
$username = "sumouser"; // Database username
$password = "Tr[~b>)wwac6Ze~G"; // Database password
// Establish connection to MySQL database
$conn = new mysqli($host, $username, $password, $dbname);
// Check if connection established successfully
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
else { echo "Connected to mysql database. <br>"; }
// Select values from MySQL database table
$sql = "SELECT id, val, val2, date, time FROM tricksumo_nodemcu"; // Update your tablename here
$result = $conn->query($sql);
echo "<center>";
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<strong> Id:</strong> " . $row["id"]. "   <strong>val:</strong> " . $row["val"]. "   <strong>val2:</strong> " . $row["val2"]. "   <strong>Date:</strong> " . $row["date"]."   <strong>Time:</strong>" .$row["time"]. "<p>";
}
} else {
echo "0 results";
}
echo "</center>";
$conn->close();
?>