In PHP, To perform any data task in MySQL database , first we have to connect MySql database to local server
This can be done as :
<?php
$servername = "localhost";
$username = "username";
$password = "password";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
We have to specify the servername, username and password to get connection from the database.
Then by using function mysqli(), we passed those variable as arguments. if there would be any error in connection, then it will be displayed and the execution halts or else it will show "Connected successfully" message.
0 Comment(s)