Advertisement
wieschoo

Untitled

May 30th, 2014
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.01 KB | None | 0 0
  1. class odb
  2. {
  3.     static $instance = null;
  4.     public static function getInstance()
  5.     {
  6.         if (null === $instance) {
  7.             $instance = new static();
  8.         }
  9.         return $instance;
  10.     }
  11.     final private function __clone(){}        // prevent cloning
  12.     final private function __wakeup(){}       // prevent unserializing
  13.  
  14.     private $PDOHost =        'localhost';
  15.     private $PDOUser =        'username';
  16.     private $PDOPass =        'password';
  17.     private $PDODB   =        'database';
  18.     private $PDO     =        null;
  19.    
  20.     protected function __construct()
  21.     {
  22.         $this->PDO = new PDO('mysql:host=' . $this->PDOHost . ';' .'dbname=' . $this->PDODB, $this->PDOUser, $this->PDOPass);  
  23.     }
  24.  
  25. }
  26.  
  27. try{
  28.  
  29.     $stmt = odb::getInstance()->prepare("SELECT COUNT(*) FROM `users` WHERE `username` = :user AND `password` = :pass");
  30.     $stmt->execute(array(":user" => "tesusername", ":pass" => "testpassword"));
  31.  
  32.     print_r($stmt->fetchAll());
  33.    
  34.    
  35. }catch(Exception $e){
  36.     die("oops");
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement