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

mysqli::$errno

(mysqli_errno) Returns the error code of the most recent function call
Name:mysqli::$errno
Category:MySQLi
Programming Language:php
One-line Description:Returns the last error code of the last function call.

Definition and usage

errno / mysqli_errno() function returns the last error code (if any) of the last function call.

Example

Example 1 - Object-Oriented Style

Returns the last error code of the last function call (if any):

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

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

// Execute the query and check for errors
if ( ! $mysqli -> query ( "INSERT INTO Persons (FirstName) VALUES ('Glenn')" ) ) {
  echo ( "Errorcode: " . $mysqli -> errno ) ;
}

$mysqli -> close ( ) ;
?>

Example 2 - Procedural Style

Returns the last error code of the last function call (if any):

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

if ( mysqli_connect_errno ( ) ) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error ( ) ;
  exit ( ) ;
}

// Execute the query and check for errors
if ( ! mysqli_query ( $con , "INSERT INTO Persons (FirstName) VALUES ('Glenn')" ) ) {
  echo ( "Errorcode: " . mysqli_errno ( $con ) ) ;
} 

mysqli_close ( $con ) ;
?>