Advertisement
Guest User

Untitled

a guest
Feb 1st, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.97 KB | None | 0 0
  1. <?php
  2. class DBConnect {
  3.     private static $_singleton;
  4.     private $_connection;
  5.    
  6.     private $DB_USERNAME = 'root';
  7.     private $DB_PASSWORD = '';
  8.     private $DB_HOST = 'localhost';
  9.    
  10.     /**
  11.      * Establish a connection to the database
  12.      */
  13.     private function __construct() {
  14.         $this->_connection = new PDO("mysql:host=$this->DB_HOST;dbname=artdb", $this->DB_USERNAME, $this->DB_PASSWORD);
  15.         $this->_connection->exec("SET CHARACTER SET utf8");
  16.     }
  17.    
  18.     /**
  19.      * Get an instance of this class
  20.      * @return Connection a connection instance
  21.      */
  22.     public static function getInstance() {
  23.         if (is_null(self::$_singleton)) {
  24.             self::$_singleton = new DBConnect();
  25.         }
  26.         return self::$_singleton;
  27.     }
  28.    
  29.     /**
  30.      * Returns the PDO database connection handler
  31.      * @return PDO database handler
  32.      */
  33.     public function getHandler() {
  34.         return $this->_connection;
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement