PHP mysqli_errno()Functions
Examples
Returns the last error code of the most recently called function:
<?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 and check for errors
if (!mysqli_query($con,"INSERT INTO websites (name) VALUES ('Rookie Tutorial')"))
{
echo("Errorcode: " . mysqli_errno($con));
}
mysqli_close($con);
?>
// 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 and check for errors
if (!mysqli_query($con,"INSERT INTO websites (name) VALUES ('Rookie Tutorial')"))
{
echo("Errorcode: " . mysqli_errno($con));
}
mysqli_close($con);
?>
Definition and Usage
The mysqli_errno() function returns the last error code of the most recently called function.
Syntax
mysqli_errno(connection);
| Parameter | Description |
|---|---|
| connection | Required. Specifies the MySQL connection to use. |
Technical Details
| Return value: | Returns the error code value. If no error occurs, returns 0. |
|---|---|
| PHP version: | 5+ |
PHP MySQLi Reference Manual Other Extensions