Advertisement
Guest User

PDO OOP Singleton

a guest
Jan 23rd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.28 KB | None | 0 0
  1. <?php
  2. class Database
  3. {
  4.     private static $_connection = null;
  5.     private function __construct() {
  6.         $_connection = new PDO($dsn, $user, $pass);
  7.     }
  8.  
  9.     public static function getDB() {
  10.         if($_connection == null) {
  11.             $_connection = new Database();
  12.         }
  13.         return $_connection;
  14.     }
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement