PHP mysqli_connect_error() Function

PHP mysqli_connect_error() Function returns description of the error from the last connection incase of a failure. If the connection is successful, then it returns Null.

PHP Version : PHP 5, PHP 7

Syntax for mysqli_connect_error():

According to Procedural,

mysqli_connect_error();

According to Object oriented,

$mysqli -> connect_error

Return values for mysqli_connect_error():

It returns error description if connection is failed. It returns NULL if connection is successful.

Example for mysqli_connect_error():

Let's see below example to understand php mysqli_connect_error() Function in details.

 

Example :

<?php
$server_name="localhost";
$username="root";
$password="";
$connection = @mysqli_connect($server_name,$username,$password);
//check mysql server connection.
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL server : " . mysqli_connect_error();
exit();
}
?>

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

77077