Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Database
- {
- // Store the single instance of Database
- private static $Instance;
- private $db_host=DB_SERVER;
- private $db_user = DB_USERNAME;
- private $db_pass = DB_PASSWORD;
- private $db_name = DB_DATABASE;
- private function __construct()
- {
- mysqli_connect($this->db_host,$this->db_user,$this->db_pass);
- mysqli_select_db($this->db_name);
- }
- // Getter method for creating/returning the single instance of this class
- public static function getInstance()
- {
- if (!self::$Instance) //if the obj doesnt exist somehow (!)
- {
- self::$Instance = new Database(); //call the constructor again (INCEPTION!)
- }
- return self::$Instance;
- }
- //can pass queries through Database object
- public function query($query)
- {
- return mysqli_query($query);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement