Advertisement
Guest User

MySQL Singleton

a guest
Apr 24th, 2014
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.43 KB | None | 0 0
  1. if(!defined('MYSQL')) {
  2.     define ('MYSQL', true);
  3.     class MySQL  {
  4.  
  5.     private static $m_pInstance;
  6.    
  7.     private function __construct() {}
  8.    
  9.     // Singleton
  10.     public static function getInstance() {
  11.         if (!self::$m_pInstance)
  12.         {
  13.         self::$m_pInstance = new PDO('mysql:host=localhost;dbname=database', 'user', 'password', array(PDO::ATTR_PERSISTENT => true));
  14.         }
  15.         return self::$m_pInstance;
  16.     }
  17.        
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement