Advertisement
Guest User

Untitled

a guest
Jan 30th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.77 KB | None | 0 0
  1. <?php
  2.  
  3. class DB {
  4.     private static $singleton;
  5.     private $connection;
  6.    
  7.     private $DB_USERNAME = "root";
  8.     private $DB_PASSWORD = "root"; //Yours should be empty
  9.     private $DB_HOST = "localhost";
  10.    
  11.     private function __construct() {
  12.         $this->connection = new PDO(
  13.                 "mysql:host=$this->DB_HOST;dbname=bookapp",
  14.                 $this->DB_USERNAME,
  15.                 $this->DB_PASSWORD
  16.         );
  17.         $this->connection->exec("SET CHARACTER SET utf8");
  18.     }
  19.    
  20.     public static function getInstance() {
  21.         if (is_null(self::$singleton)) {
  22.             self::$singleton = new DB();
  23.         }
  24.         return self::$singleton;
  25.     }
  26.    
  27.     public function getHandler() {
  28.         return $this->connection;
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement