コード例 #1
0
ファイル: DriverAwareTrait.php プロジェクト: phossa/phossa-db
 /**
  * {@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
ファイル: TransactionTrait.php プロジェクト: phossa/phossa-db
 /**
  * {@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
ファイル: ConnectTrait.php プロジェクト: phossa/phossa-db
 /**
  * {@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
ファイル: Manager.php プロジェクト: phossa/phossa-db
 /**
  * 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
ファイル: ResultAbstract.php プロジェクト: phossa/phossa-db
 /**
  * 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
ファイル: DriverAbstract.php プロジェクト: phossa/phossa-db
 /**
  * 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);
     }
 }