Database connection code of PHP.
We are here using xampp web server.
// For creating a database, open xampp control panel, and turn on the Apache server and MySQL database.
// Then click the admin of the MySQL database, then it will open phpmyadmin in your browser. Or you can manually type in your browser, localhost/phpmyadmin/
// After, create a database named db_name. I just gave the name db_name, You can give the name in your own way.
// Create a file like name.php , and save that file into xamp/htdocs/newfolder/
// After writing the programe, open your browser and navigate into localhost/newfolder/name.php
// So there we can see if the connection is successful o r not.
// If the connection to the database is successful it displays the message of success. If it fails, it shows failed.
//Database connection code of PHP
<?php
$conn = mysqli_connect("localhost","root","","db_name");
if($conn)
}
echo "Connection success.";
}
else
{
echo "Connection Failed.";
}
?>
// $conn is a variable.
// mysqli_connect() is a function.
// localhost is our host.
// root is the username of phpmyadmin.
// And the password of the phpmyadmin is null, so that’s why we entered only a double inverted comma ("").
// db_name is the name of our database.
// Then, we are checking the connection is succes or not with the if loop.
I hope you understood correctly.
If you have any doubts, please ask the question in the comment section.