Beispiel #1
0
 /**
  * 初始化 PDO对象
  *
  * @access public
  * @param array $configs PDO#__construct 使用数组来指定第一~第三个参数(默认值:生产环境的数据库)
  * @param array $driver_options PDO#__construct 第四个参数(默认:「SET CHARACTER SET `utf8`」)
  * @return PDO 对象
  */
 public static function initializeInstance($configs = array(), $driver_options = array())
 {
     if (empty($configs)) {
         $configs = IniFileManager::getByFileName(self::FILE_NAME);
     }
     if (empty($configs)) {
         throw new Exception('Could not get configuration of "' . self::FILE_NAME . '".');
     }
     if (empty($driver_options)) {
         $driver_options = Database::$DEFAULT_DRIVER_OPTIONS;
     }
     $pdo = new ExtPDO($configs[self::CONFIG_KEY_DSN], $configs[self::CONFIG_KEY_USER], $configs[self::CONFIG_KEY_PASSWORD], $driver_options);
     // 设置错误报告:抛出异常
     $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     //$pdo->setAttribute( PDO::ATTR_EMULATE_PREPARES, false );
     return $pdo;
 }