I wrote a class to create an automated connection with MySQL and create queries. Here\'s how it looks like:
include(\"constants.php\"); class MySQLDB {
Have a look at the __destruct() method add add that into your class and your close connection in there