0% found this document useful (0 votes)
11 views2 pages

Dbreadphp

This PHP script connects to a MySQL database using specified credentials and retrieves data from a table named 'nodemcu_table'. It checks for a successful connection and, if successful, queries the database to display the results in a formatted manner. If no results are found, it outputs '0 results'.

Uploaded by

chouaieb.ali88
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

Dbreadphp

This PHP script connects to a MySQL database using specified credentials and retrieves data from a table named 'nodemcu_table'. It checks for a successful connection and, if successful, queries the database to display the results in a formatted manner. If no results are found, it outputs '0 results'.

Uploaded by

chouaieb.ali88
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

// 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 nodemcu_table"; // 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"]. " &nbsp <strong>val:</strong> "
. $row["val"]. " &nbsp <strong>val2:</strong> " . $row["val2"]. " &nbsp
<strong>Date:</strong> " . $row["date"]." &nbsp <strong>Time:</strong>" .
$row["time"]. "<p>";

}
} else {
echo "0 results";
}

echo "</center>";
$conn->close();

?>

You might also like