Syntax :
mysqli_connect(host,username,password,dbname);
Code :
<?php
$con=mysqli_connect("example.com","peter","abc123","my_db");
// Check connection
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
else {
echo "Successfully Connected";
}
mysqli_close($con);
?>
-----------------
"example.com" --> Host
"peter" --------> Username
"abc123" -------> Password
"my_db" --------> Database name
OutPut :
mysqli_connect(host,username,password,dbname);
Code :
<?php
$con=mysqli_connect("example.com","peter","abc123","my_db");
// Check connection
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
else {
echo "Successfully Connected";
}
mysqli_close($con);
?>
-----------------
"example.com" --> Host
"peter" --------> Username
"abc123" -------> Password
"my_db" --------> Database name
OutPut :
Comments