POST POST BY - slowmotion
How to close MySQL connection, only if it is open?

Closing MySQL connection is very important in order to avoid your active queries going into sleep mode. MySQL connection  once opened should always be closed - you can not keep it permanently active or open.

The best method to close it is by checking either it is ON, and if it is ON, then only close it.

Syntax to close the connection is as below:





This code, first checks whether the MySQL connection ($conn) is ON (i.e. is available as resource) or not and if it is ON, the method 'close()' is called to permanently  close it.

# MySQL # DBConnection
Technology >> @slowmotion / 1,443 Views / Apr 02, 2016
Share This Post: