Exemplo n.º 1
0
 public static function getDBH()
 {
     if (empty(self::$dbh) || !is_object(self::$dbh) || get_class(self::$dbh) != 'PDO') {
         try {
             // Connect to the SQL server
             if (DB_DRIVER == 'sqlite') {
                 self::$dbh = new PDO(DB_DRIVER . ':' . DB_FILE);
             } else {
                 self::$dbh = new PDO(DB_DRIVER . ':host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USER, DB_PASSWORD);
             }
             // Set ERRORMODE to exceptions
             self::$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
         } catch (PDOException $e) {
             echo $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine();
             die;
         }
     }
     return self::$dbh;
 }