11.5.3.4 use script language to connect a database
Connect webpage to database using PHP
Scenario
The school holds competitions among Shanyraks. For each useful action, Shanyrak points are scored. The deputy director keeps a record of all the items in the notebook. Counting and identifying all points takes a long time, and there may be errors. Automate the work.
Use PHP and MySQLi to connect with database Scenario
Create file connect.php in folder Project (in htdocs).
<?php
$servername = "localhost"; // name of server
$username = "username"; // name of user
$password = "password"; // password of user
$db = "scenario"; // name of database in phpMyAdmin // Create connection
$conn = mysqli_connect($servername, $username, $password, $db); // Check connection
if (!$conn) { // if connection False
die("Connection failed: " . mysqli_connect_error()); // show message about error connection and stop php script
}
echo "Connected successfully"; // show message if connection True
?>