Connect MySQL using PHP
MYSQLI_CONNECT()
mysqli_connect consists of 4 arguments.
mysqli_connect($host_name, $username, $password, $database_name);
$host_name : Host name or an ip address. (“localhost” is most likely the host name if you are using a cpanel server).
$username : Privileged username of MySQL. “root” is the default username.
$password : Password of MySQL. ” ” is the default password.
$database_name : Database you created in MySQL.
Example Program:
//declare connection requirements
$host_name = “localhost”;
$username = “root”;
$password = “”;
$database_name = “database_2015”;
//connection establishing
//store the connection in a variable named $conn or anything.
$conn = mysqli_connect($host_name, $username, $password, $database_name);
//check connection is successful or not
if(mysqli_connect_errno()){
die(“ERROR :”.mysqli_connect_error());
}
else{
echo “Connection Successful”;
}
?>
mysqli_connect_errno()
This function returns the error code from last connect call.
0 comments: