I am going to use mysqli_close($connection)
to close the $connection
. But Before Closing I need to ensure that the concerned connection is open.
Got to check if there is a connection before ping
CAUTION!!!
ALWAYS do your job and explicity close your connection because other things may go wrong before php closes it by script ending
<?php
$link = mysqli_connect("localhost", "username", "pwd", "mydatabase");
if (
$link // has a connection ?
&& mysqli_ping($link) // is it connected ?
) {
mysqli_close($link)
}
?>