PHP mysqli connect_error() Function

PHP MySQLi Reference : Return the error description from the last connection error, if any

Definition and Usage

The connect_error / mysqli_connect_error() function returns the error description from the last connection error, if any.

Syntax

Object oriented style:

$mysqli -> connect_error

Procedural style:

mysqli_connect_error();

Technical Details

Return Value: Returns a string that describes the error. NULL if no error occurred
PHP Version: 5+

Example - Procedural style

Return the error description from the last connection error, if any:

<?php
$con = mysqli_connect("localhost","my_user","my_password","my_db");

// Check connection
if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  exit();
}
?>

❮ PHP MySQLi Reference