I have a class that allows a PDO connection which sets itself up. When I want to use the connection I can use:
$db = $factory->create('db');
However, I wanted to just be able to do:
global $db;
Anytime I want to use the database.
Would this work?
$db = function(){
$con = $factory->create('db');
return $con;
};
global $db;
This way, I can close the connection and then open it again at any point. Example:
global $db;
$db->close();
// Re-open
global $db;
Or how could I possibly do this? References would be so appreciated as I have searched a lot.
Thanks in advance.