Advertisement
dead__

Untitled

Dec 2nd, 2012
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.73 KB | None | 0 0
  1. <?php
  2.     class DatabaseException extends Exception { }
  3.    
  4.     final class core {
  5.         public static $database = null;
  6.         public static $user = null;
  7.        
  8.         public static function getUser() {
  9.             if(empty(self::$user) || self::$user === null) self::$user = new user();
  10.             return self::$user;
  11.         }
  12.        
  13.         public static function getDatabase() {
  14.             $dsn = 'mysql:dbname=' . config::$mysql['database'] . ';host=' . config::$mysql['host'];
  15.             try {
  16.                 self::$database = new PDO($dsn, config::$mysql['user'], config::$mysql['pass']);
  17.                 self::$database->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  18.             } catch (PDOException $e) {
  19.                 throw new DatabaseException($e->getMessage());
  20.                 //exit;
  21.             }
  22.             return self::$database;
  23.         }
  24.     }
  25. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement