PHP mysqli: connect_errno() function
mysqli_connect_errno() function / mysqli::$connect_errno
The mysqli_connect_errno() function / mysqli::$connect_errno returns the error code from the last connection error, if any.
Syntax:
Object oriented style
int $mysqli->connect_errno;
Procedural style
int mysqli_connect_errno ( void )
Usage: Procedural style
mysqli_commit(connection);
Return value:
An error code value for the last call to mysqli_connect(), if it failed. zero means no error occurred.
Version: PHP 5, PHP 7
Example of object oriented style:
<?php
$mysqli = @new mysqli('localhost', 'user1', 'datasoft123', 'hr');
if ($mysqli->connect_errno) {
die('Connect Error: ' . $mysqli->connect_errno);
}
?>
Example of procedural style:
<?php
$link = @mysqli_connect('localhost', 'user1', 'datasoft123', 'hr');
if (!$link) {
die('Connect Error: ' . mysqli_connect_errno());
}
?>
Output:
Connect Error: 1045
Example:
<?php
$con=mysqli_connect("localhost","user1","datasoft123","hr");
// Check connection
if (!$con)
{
die("Connection error: " . mysqli_connect_errno());
}
?>
Output:
Connection error: 0
See also
Previous: commit
Next: connect_error
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/php/function-reference/mysqli_connect_errno.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics