Before access data in a database, we must open a database connection to the MySQL server.
In PHP, using the mysqli_connect() function.
mysqli_connect(host,username,password,dbname);
<?php
// Create a connection
$con=mysqli_connect(“example.com”,”user01″,”password”,”my_db”);// Check connection
if (mysqli_connect_errno())
{
echo “Failed to connect to MySQL: ” . mysqli_connect_error();
}
$con=mysqli_connect(“example.com”,”user01″,”password”,”my_db”);// Check connection
if (mysqli_connect_errno())
{
echo “Failed to connect to MySQL: ” . mysqli_connect_error();
}
?>