PHP mysqli connect_errno() Function
Example - Object Oriented style
Return an error code from the last connection error, if any:
<?php
$mysqli = new mysqli("localhost","my_user","my_password","my_db");
// Check connection
if ($mysqli -> connect_errno) {
echo "Failed to connect to MySQL: " . $mysqli -> connect_error;
exit();
}
?>
Look at example of procedural style at the bottom.
Definition and Usage
The connect_errno / mysqli_connect_errno() function returns the error code from the last connection error, if any.
Syntax
Object oriented style:
$mysqli -> connect_errno
Procedural style:
mysqli_connect_errno()
Technical Details
Return Value: | Returns an error code value. Zero if no error occurred |
---|---|
PHP Version: | 5+ |
Example - Procedural style
Return an error code from the last connection error, if any:
<?php
$con = mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit();
}
?>
❮ PHP MySQLi Reference
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.