How to use mysqli_connect() function in PHP?
The mysqli_connect() function in php is used to open a new connection to the MySQL server.
The syntax for the mysqli() function in php is written below:
mysqli_connect(host, username, password, dbname, port, socket);
host server name or an IP address
username Optional. For the MySQL username
password Optional. For the MySQL password
dbname Optional. For the default database to be used
port Optional. For the port number to attempt to connect to the MySQL server
socket Optional. Specifies the socket or named pipe to be used
This function return value is an object representing the connection to the MySQL server
<?php
$con = mysqli_connect("localhost" ,"root" ,"" ,"demo");
// check connection
if(mysqli_connect_errno())
{
echo "connection failed".mysqli_connect_errno();
}
else
{
echo "database connection successfully";
}
?>