PHP mysqli close() Function
Example - Object Oriented style
Close a previously opened database connection:
<?php
$mysqli = new mysqli("localhost","my_user","my_password","my_db");
if ($mysqli -> connect_errno) {
echo "Failed to connect to MySQL: " . $mysqli -> connect_error;
exit();
}
// ....some PHP code...
$mysqli -> close();
?>
Look at example of procedural style at the bottom.
Definition and Usage
The close() / mysqli_close() function closes a previously opened database connection.
Syntax
Object oriented style:
$mysqli -> close()
Procedural style:
mysqli_close(connection)
Parameter Values
Parameter | Description |
---|---|
connection | Required. Specifies the MySQL connection to close |
Technical Details
Return Value: | TRUE on success. FALSE on failure |
---|---|
PHP Version: | 5+ |
Example - Procedural style
Close a previously opened database connection:
<?php
$con=mysqli_connect("localhost","my_user","my_password","my_db");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit;
}
// ....some PHP code...
mysqli_close($con);
?>
❮ PHP MySQLi Reference