Current Location: Home> Function Categories> mysqli::$connect_error

mysqli::$connect_error

(mysqli_connect_error) Returns the string description of the last connection error
Name:mysqli::$connect_error
Category:MySQLi
Programming Language:php
One-line Description:Returns the error description of the last connection error.

Definition and usage

connect_error / mysqli_connect_error() function returns the error description of the last connection error (if any).

Example

Example 1 - Object-Oriented Style

Returns the error description of the last connection error (if any):

 <?php
$mysqli = new mysqli ( "localhost" , "my_user" , "my_password" , "my_db" ) ;

// Check the connection
if ( $mysqli -> connect_errno ) {
  echo "Failed to connect to MySQL: " . $mysqli -> connect_error ;
  exit ( ) ;
}
?>

Example 2 - Procedural Style

Returns the error description of the last connection error (if any):

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

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