Advertisement
Guest User

Untitled

a guest
Apr 20th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.11 KB | None | 0 0
  1.        class Database
  2.         {
  3.             // Store the single instance of Database
  4.             private static $Instance;
  5.  
  6.             private $db_host=DB_SERVER;
  7.             private $db_user = DB_USERNAME;
  8.             private $db_pass = DB_PASSWORD;
  9.             private $db_name = DB_DATABASE;
  10.  
  11.            
  12.             private function __construct()
  13.             {
  14.                 mysqli_connect($this->db_host,$this->db_user,$this->db_pass);
  15.                 mysqli_select_db($this->db_name);
  16.             }
  17.  
  18.             // Getter method for creating/returning the single instance of this class
  19.             public static function getInstance()
  20.             {
  21.                 if (!self::$Instance) //if the obj doesnt exist somehow (!)
  22.                 {
  23.                     self::$Instance = new Database(); //call the constructor again (INCEPTION!)
  24.                 }
  25.                 return self::$Instance;
  26.             }
  27.  
  28.             //can pass queries through Database object
  29.             public function query($query)
  30.             {
  31.                return mysqli_query($query);
  32.             }
  33.  
  34.          }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement