Advertisement
Guest User

Database Class - Pagination

a guest
Apr 26th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.94 KB | None | 0 0
  1. <?php
  2.  
  3. class Database
  4. {
  5.     private $conn;
  6.     private static $instance = null;
  7.  
  8.     private $host = 'localhost';
  9.     private $db = 'test_db';
  10.     private $username = 'test';
  11.     private $password = 'test';
  12.  
  13.     public static function getInstance()
  14.     {
  15.         if (is_null(static::$instance)) {
  16.             static::$instance = new static;
  17.         }
  18.  
  19.         return static::$instance;
  20.     }
  21.  
  22.     private function __construct()
  23.     {
  24.         try {
  25.             $this->conn = new PDO('mysql:host=' . $this->host . ';dbname=' . $this->db, $this->username, $this->password);
  26.             $this->conn->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
  27.         } catch (\PDOException $e) {
  28.             die('Unable to connect to database:' . $e->getMessage());
  29.         }
  30.     }
  31.  
  32.     private function __clone() {}
  33.  
  34.     private function __wakeup() {}
  35.  
  36.     public function getConnection()
  37.     {
  38.         return $this->conn;
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement