Beispiel #1
0
 /**
  * {@inheritdoc}
  * */
 protected function _connect(persistConfig $config)
 {
     try {
         $resource = new \PDO($config->getDSN(), $config->get('username'), $config->get('password'));
         # throws exception if anything wrong
         $resource->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
         # get values as objects
         $resource->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_OBJ);
         # column names aways lowercase
         $resource->setAttribute(\PDO::ATTR_CASE, \PDO::CASE_LOWER);
         return $resource;
     } catch (\PDOException $pdoe) {
         # @todo um log com o error do PDO devera ser guardo
         throw new PersistException($pdoe->getMessage(), $pdoe->getCode(), $pdoe);
     }
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  * */
 protected function _connect(persistConfig $config)
 {
     # por algum motivo desonhecido existe momomentos que o hash obtido em $config->hash()
     # por isso foi necessario recuperar os valores de $config e coloca-los em um array limpo
     $data = array('adapter' => $config->get('adapter'), 'driver' => $config->get('driver'));
     $hash = md5(json_encode($data));
     if (!isset(self::$_sqlConnn[$hash])) {
         try {
             $resource = new \PDO($config->getDSN());
             $resource->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
             $resource->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_OBJ);
             $resource->setAttribute(\PDO::ATTR_CASE, \PDO::CASE_LOWER);
             PersistException::throwsExceptionIfParamIsNull($resource, self::CONNECT_CANNOT_CONNECT);
             self::$_sqlConnn[$hash] = $resource;
         } catch (\PDOException $pdoe) {
             # @todo um log com o error do PDO devera ser guardo;
             // @codeCoverageIgnoreStart
             throw new PersistException($pdoe->getMessage(), $pdoe->getCode());
             // @codeCoverageIgnoreEnd
         }
     }
     return self::$_sqlConnn[$hash];
 }