MySQL Database in PHP

 MySQL Database in PHP


PHP can be used to interact with a MySQL database. MySQL functions are used to connect to the database, execute queries, and fetch results.

Example:


php


// connect to database

$servername = "localhost";

$username = "username";

$password = "password";

$dbname = "myDB";


$conn = mysqli_connect($servername, $username, $password, $dbname);


// execute query

$sql = "SELECT * FROM customers";

$result = mysqli_query($conn, $sql);


// fetch results

while($row = mysqli_fetch_assoc($result)) {

    echo "Name: " . $row["name"] . " - Email: " . $row["email"];

}

No comments:

Post a Comment

The Importance of Cybersecurity in the Digital Age

 The Importance of Cybersecurity in the Digital Age Introduction: In today's digital age, where technology is deeply intertwined with ev...