Skip to content

Instantly share code, notes, and snippets.

@slaith
Created September 6, 2013 04:52
Show Gist options
  • Save slaith/6459693 to your computer and use it in GitHub Desktop.
Save slaith/6459693 to your computer and use it in GitHub Desktop.
Database singleton
<?php
class Database{
static private $_instance;
static $hostname="";
static $username="";
static $password="";
static $database="";
$conn;
static function getInstance(){
if(self::$_instance)
return self::$_instance;
else
return new self;
}
public __construct(){
$this->conn = mysqli_connect(self:$hostname,self::$username,self::$password,self::$database);
}
//Delegatesfunction calls to $db->conn->method to $db->method
public function __call($method, $args) {
call_user_func_array(array($this->conn,$method),$args); //OR array($args), I am not sure
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment