} public function runQuery($query) { echo 'I am running: ' . $query . '<br/>'; } } // Make this one a singleton i.e. I only want one socket connection to be made, ever! class RedisDatabase { public static $instance; private function __construct() { echo 'I am making a socket connection to redis...'; } public static function getInstance() { if (!isset(self::$instance)) { self::$instance = new RedisDatabase(); } return self::$instance; } } ################################## ##index.php### ################################## $db = MySqlDatabase::getInstance(); $query = 'select * from foo'; $db->runQuery($query); $db = MySqlDatabase::getInstance(); $query = 'select * from bar'; $db->runQuery($query);
function __construct($db_host, $db_user, $db_password, $db_name) { $this->db = MySqlDatabase::getInstance(); $this->db->connect($db_host, $db_user, $db_password, $db_name); $this->notifications_table = 'notifications'; }