How to Check Whether mysqli connection is open before closing it

后端 未结 7 1847
野趣味
野趣味 2021-02-04 00:30

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.

<
7条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-04 01:21

    Try this:

    function close_connection(){
        $thread = $mysqli->thread_id;
        $mysqli->close();
        $mysqli->kill($thread);
    
    }
    

    That will close the connection you opened using object oriented style like this:

    $mysqli = new mysqli($db_server, $db_username, $db_password, $db_name);
    

    That's the basic idea, but if you're using the procedural style, I'm sure you'll be able to custom the code as you need.

提交回复
热议问题