In PHP, mysqli_connect_errno() returns the error code from the last connection attempt.
In object-oriented style you read the $mysqli->connect_errno property on the connection object. The procedural function takes no arguments and reports the most recent connect failure code, or 0 when the last attempt succeeded.
Syntax
Call mysqli_connect_errno() with the values you need. Start with this line.
PHP
$code = mysqli_connect_errno();
Call
What it does
mysqli_connect_errno()
Returns 0 on success, or a MySQL error code on failure.
$mysqli->connect_errno
Object-oriented property on the mysqli instance.
mysqli_connect_errno() !== 0
True when the last connect attempt failed.
Pair this with mysqli_connect_error() for the message text. For errors after a successful connect, use mysqli_errno() / $mysqli->errno instead.
Library declarations
PHP
mysqli_connect_errno(): int
Parameters
Parameter
Description
—
This function takes no parameters.
Return Value
Return Value
Description
int
0 when the last connection attempt succeeded; otherwise a MySQL error code such as 1045.
1045 is the common access-denied code in sample output.
Frequently Asked Questions
An integer error code from the last connection attempt. 0 means success.
No. The procedural function has an empty parameter list. In OO style you read $mysqli->connect_errno on the object returned by new mysqli().
connect_errno is only about connecting. mysqli_errno() reports errors from later operations on an open connection.
1045 is the usual Access denied code. Always also read the error string for details.
Many apps enable MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT so connect failures throw. You can still read connect_errno when you catch or when exceptions are off.