PHP mysqli_error()Function

PHP MySQLi 参考手册PHP MySQLi Reference Manual

Examples

Returns the last error description of the most recent function call:

<?php
// Assume database username: root, password: 123456, database: EXAMPLE
$con=mysqli_connect("localhost","root","123456","EXAMPLE");
if (
mysqli_connect_errno($con))
{
    echo
"Connection to MySQL failed: ". mysqli_connect_error();
}

// Execute the query, check for errors
if (!mysqli_query($con,"INSERT INTO websites (name) VALUES ('Rookie Tutorial')"))
{
    echo(
"Error description: ". mysqli_error($con));
}

mysqli_close($con);
?>

Definition and Usage

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


Syntax

mysqli_error(connection);

Parameters Description
connection Required. Specifies the MySQL connection to use.

Technical Details

Return value: Returns a string with the error description. Returns "" if no error occurs.
PHP Version: 5+


PHP MySQLi 参考手册PHP MySQLi Reference Manual Other Extensions