示例#1
0
 public static function getConnection()
 {
     if (self::$_db == null) {
         // No PDO exists yet, so make one and send it back.
         try {
             self::$_db = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USERNAME, DB_PASSWORD, array(PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
         } catch (PDOException $e) {
             die('<h1>Sorry. The Database connection is temporarily unavailable.</h1>');
         }
         return self::$_db;
     } else {
         return self::$_db;
     }
 }