예제 #1
0
 /**
  * {@inheritDoc}
  */
 public function getDriver()
 {
     if (null === $this->driver) {
         throw new LogicException(Message::get(Message::DB_SQL_NO_DRIVER), Message::DB_SQL_NO_DRIVER);
     }
     return $this->driver;
 }
예제 #2
0
 /**
  * {@inheritDoc}
  */
 public function getProfiler()
 {
     if ($this->isProfiling()) {
         return $this->profiler;
     } else {
         throw new LogicException(Message::get(Message::DB_UNKNOWN_PROFILER), Message::DB_UNKNOWN_PROFILER);
     }
 }
예제 #3
0
 /**
  * {@inheritDoc}
  */
 public function rollback()
 {
     if ($this->isConnected()) {
         if (!$this->inTransaction()) {
             throw new RuntimeException(Message::get(Message::DB_INVALID_ROLLBACK), Message::DB_INVALID_ROLLBACK);
         }
         $this->realRollback();
     }
     $this->transaction = false;
     return $this;
 }
예제 #4
0
 /**
  * {@inheritDoc}
  */
 public function connect()
 {
     if ($this->isConnected()) {
         return $this;
     }
     // connect using parameters
     if (empty($this->connect_parameters)) {
         throw new LogicException(Message::get(Message::DB_CONNECT_MISSING), Message::DB_CONNECT_MISSING);
     } else {
         try {
             $this->realConnect($this->connect_parameters);
         } catch (\Exception $e) {
             throw new LogicException(Message::get(Message::DB_CONNECT_FAIL, $e->getMessage()), Message::DB_CONNECT_FAIL);
         }
     }
     return $this;
 }
예제 #5
0
파일: Driver.php 프로젝트: phossa/phossa-db
 /**
  * {@inheritDoc}
  */
 protected function realGetAttribute($attribute)
 {
     if (is_string($attribute)) {
         if (defined($attribute)) {
             return $this->link->getAttribute(constant($attribute));
         } else {
             throw new LogicException(Message::get(Message::DB_UNKNOWN_ATTRIBUTE, $attribute), Message::DB_UNKNOWN_ATTRIBUTE);
         }
     } else {
         return $this->link->getAttribute($attribute);
     }
 }
예제 #6
0
 /**
  * Get a driver with a tag matched
  *
  * {@inheritDoc}
  */
 public function getDriver($tag = '')
 {
     // match drivers
     $matched = $this->driverMatcher($tag);
     // match found
     if (count($matched) > 0) {
         // pick a random driver
         return $this->drivers[$matched[rand(1, count($matched)) - 1]];
         // not found
     } else {
         throw new NotFoundException(Message::get(Message::DB_DRIVER_NOTFOUND), Message::DB_DRIVER_NOTFOUND);
     }
 }
예제 #7
0
 /**
  * Throw exception if fetched already
  *
  * @throws RuntimeException if fetched already
  * @access protected
  */
 protected function exceptionIfFetchedAlready()
 {
     if ($this->fetched) {
         throw new RuntimeException(Message::get(Message::DB_FETCHED_ALREADY), Message::DB_FETCHED_ALREADY);
     }
 }
예제 #8
0
 /**
  * {@inheritDoc}
  */
 public function execute(array $parameters = [])
 {
     // flush driver error
     $this->flushError();
     // init execution time
     $this->execution_time = 0.0;
     if ($this->prepared) {
         $result = clone $this->result_prototype;
         $result($this->prepared);
         // close previous statement if any
         $this->closePrevious();
         // start time
         $time = microtime(true);
         // execute
         try {
             if (false === $this->realExecute($parameters)) {
                 // set driver error
                 $this->setError($this->prepared);
                 return false;
             }
         } catch (\Exception $e) {
             $this->setError($this->prepared);
             return false;
         }
         $this->execution_time = microtime(true) - $time;
         return $result;
     } else {
         $this->setError(Message::get(Message::DB_SQL_NOT_PREPARED));
         return false;
     }
 }
예제 #9
0
 /**
  * constructor
  *
  * @param  array|resource $connectInfo
  * @throws LogicException driver specific extension not loaded
  * @throws InvalidArgumentException if link type not right
  * @access public
  */
 public function __construct($connectInfo)
 {
     // check driver specific extension
     if (!$this->extensionLoaded()) {
         throw new LogicException(Message::get(Message::DB_EXTENSION_NOT_LOAD, get_class($this)), Message::DB_EXTENSION_NOT_LOAD);
     }
     // set connect info
     try {
         if (is_array($connectInfo)) {
             $this->connect_parameters = $connectInfo;
         } elseif (!$this->setConnectLink($connectInfo)) {
             throw new InvalidArgumentException(Message::get(Message::DB_INVALID_DRIVER, gettype($connectInfo)), Message::DB_INVALID_DRIVER);
         }
     } catch (\Exception $e) {
         throw new InvalidArgumentException(Message::get(Message::DB_INVALID_LINK, $e->getMessage()), Message::DB_INVALID_LINK, $e);
     }
 }