Create a Database and Table in MySQL.docx
Create a Database and Table in MySQL.docx
DESC emp;
INSERT INTO emp (name, email) VALUES ('John Doe', '[email protected]');
INSERT INTO emp (name, email) VALUES ('Jane Doe', '[email protected]');
Select * from emp;
Exit MySQL:
Exit
Add the following PHP code to connect to MySQL and retrieve data from the users table:
php
Copy
<?php
$servername = "localhost";
$username = "root"; // default MySQL root user
$password = "your_mysql_root_password"; // replace with your MySQL root
password
$dbname = "simpledb";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "id: " . $row["id"]. " - Name: " . $row["name"]. " - Email: " .
$row["email"]. "<br>";
}
} else {
echo "0 results";
}
$conn->close();
?>
arduino
Copy
http://localhost/db_connect.php
You should see the data from your users table displayed in the browser, such as:
bash
Copy
id: 1 - Name: John Doe - Email: [email protected]
id: 2 - Name: Jane Doe - Email: [email protected]
7. Troubleshooting