Current Location: Home> Function Categories> mysqli::close

mysqli::close

(mysqli_close) Close previously opened database connection
Name:mysqli::close
Category:MySQLi
Programming Language:php
One-line Description:Close the previously opened database connection.

Definition and usage

The close() / mysqli_close() function is used to close a previously opened database connection.

Example

Example 1 - Object-Oriented Style

Close the 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 ( ) ;
?>

Example 2 - Procedural Style

Close the 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 ) ;
?>
Similar Functions
Popular Articles