How to Check Whether mysqli connection is open before closing it

后端 未结 7 1839
野趣味
野趣味 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-04 01:13

    Just don't close it. That would be the best solution ever.

    99.9% of time it's perfectly ok to leave the connection alone, PHP will close it for you.

    Only if your script has to perform some heavy time consuming task that doesn't involve a database interaction, you may want to close the connection before starting this operation. But in this case you will have the connection deliberately open as there will be no random closures scattered around the code and therefore will be no need to check whether it is closed already. Hence, just close it, in this particular but extremely rare case.

    All other time just leave it alone.

提交回复
热议问题