PHP mysqli_error() Function

Definition

The mysqli_error() function returns the last error for the most recent function call.

Syntax

PHP mysqli_error() Function has the following syntax.

mysqli_error(connection);

Parameter

ParameterIs RequiredDescription
connectionRequired.MySQL connection

Return

A string that describes the error. An empty string if no error occurred.

Example

Get the last error for the most recent function call


<?php/*from www .j a  v a2 s .  c  o  m*/
$con=mysqli_connect("localhost","my_user","my_password","my_db");

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

// Perform a query, check for error
if (!mysqli_query($con,"INSERT INTO Persons (FirstName) VALUES ('Jack')")){
  echo("Error description: " . mysqli_error($con));
}

mysqli_close($con);
?>




















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions