Hello guy, today we will learn the close function and it is a function of PHP mysqli. And it does close a previously opened database connection.
Here have two types of close functions: 1. Called close() function that is used in the Object-Oriented type of query. 2. Called mysqli_close() function that is used in the Procedural type of query. The close() / mysqli_close() function closes a previously opened database connection. connection: Required. Specifies the MySQL connection to close Return Value: TRUE on success. FALSE on failure PHP Version: 5+<!DOCTYPE html>
<html>
<head>
<title>Object Oriented style</title>
<style>
body{ font-size: xx-large; }
</style>
</head>
<body>
<h3>Object Oriented style</h3>
<hr>
<?php
//DB connection
// new mysqli(host, user, password, database name);
$DBConnection = new mysqli("localhost:3308", "bit", "bitbyte", "bit_yt");
//Check connection
if($DBConnection->connect_error){
echo "Failed to connect to MySQL: ". $DBConnection->connect_error;
exit();
}
//Code...
$DBConnection -> close();
$sql = $DBConnection -> query("SELECT * FROM students");
print_r($sql -> fetch_all(MYSQLI_ASSOC));
?>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Procedural style</title>
<style>
body{ font-size: xx-large; }
</style>
</head>
<body>
<h3>Procedural style</h3>
<hr>
<?php
//DB connection
// new mysqli(host, user, password, database name);
$DBConnection = mysqli_connect("localhost:3308", "bit", "bitbyte", "bit_yt");
//Check connection
if(mysqli_connect_errno()){
echo "Failed to connect to MySQL: ". mysqli_connect_error();
exit();
}
//Code...
mysqli_close($DBConnection);
$sql = mysqli_query($DBConnection, "SELECT * FROM students");
print_r(mysqli_fetch_all($sql, MYSQLI_ASSOC));
?>
</body>
</html>
Comments
Post a Comment