PHP mysqli connect_error() Function
Example - Object Oriented style
Return the error description 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_error / mysqli_connect_error() function returns the error description from the last connection error, if any.
Syntax
Object oriented style:
$mysqli -> connect_error
Procedural style:
mysqli_connect_error();
Technical Details
Return Value: | Returns a string that describes the error. NULL if no error occurred |
---|---|
PHP Version: | 5+ |
Example - Procedural style
Return the error description 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.