Exemplo n.º 1
0
 /**
  * Connects to the database
  *
  * @param XML $config Database-related piece of config.xml
  * @return bool Success
  */
 public static function connect($config)
 {
     if (!$config || !(string) $config->name) {
         throw new DBException("Please provide a valid configuration object.", E_USER_ERROR);
     }
     try {
         $settings = static::config($config);
         self::$pdo = new PDO($settings['conn'], $settings['login'], $settings['pass'], $settings['opts']);
         if ($settings['type'] == 'mysql') {
             self::query("SET NAMES utf8");
         }
         return self::$pdo;
     } catch (\PDOException $e) {
         throw new DBException("Can't connect to database: " . $e->getMessage(), E_USER_ERROR);
     }
 }