The mysqli_errno() function returns the last error code for the most recent function call.
PHP mysqli_errno() Function has the following syntax.
mysqli_errno(connection);
Parameter | Is Required | Description |
---|---|---|
connection | Required. | MySQL connection |
It returns an error code value or Zero if no error occurred.
Get the last error code for the most recent function call.
<?php//from ww w. j a v a 2s. c om
$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("Errorcode: " . mysqli_errno($con));
}
mysqli_close($con);
?>