Пример #1
0
 /**
  * Executes a prepared statement.
  *
  * @param array $params OPTIONAL Values to bind to parameter placeholders.
  * @return bool
  */
 public function execute(array $params = null)
 {
     /*
      * Simple case - no query profiler to manage.
      */
     if ($this->_queryId === null) {
         return $this->_execute($params);
     }
     /*
      * Do the same thing, but with query profiler
      * management before and after the execute.
      */
     $prof = $this->_adapter->getProfiler();
     $qp = $prof->getQueryProfile($this->_queryId);
     if ($qp->hasEnded()) {
         $this->_queryId = $prof->queryClone($qp);
         $qp = $prof->getQueryProfile($this->_queryId);
     }
     if ($params !== null) {
         $qp->bindParams($params);
     } else {
         $qp->bindParams($this->_bindParam);
     }
     $qp->start($this->_queryId);
     $retval = $this->_execute($params);
     $prof->queryEnd($this->_queryId);
     return $retval;
 }
Пример #2
0
 /**
  * Render LIMIT OFFSET clause
  *
  * @param string   $sql SQL query
  * @return string
  */
 protected function _renderLimitoffset($sql)
 {
     $count = 0;
     $offset = 0;
     if (!empty($this->_parts[self::LIMIT_OFFSET])) {
         $offset = (int) $this->_parts[self::LIMIT_OFFSET];
         $count = PHP_INT_MAX;
     }
     if (!empty($this->_parts[self::LIMIT_COUNT])) {
         $count = (int) $this->_parts[self::LIMIT_COUNT];
     }
     /*
      * Add limits clause
      */
     if ($count > 0) {
         $sql = trim($this->_adapter->limit($sql, $count, $offset));
     }
     return $sql;
 }
Пример #3
0
 /**
  * Special handling for PDO query().
  * All bind parameter names must begin with ':'
  *
  * @param string|\Micro\Database\Select $sql The SQL statement with placeholders.
  * @param array $bind An array of data to bind to the placeholders.
  * @return \Micro\Database\Statement\Pdo
  * @throws \Micro\Database\Statement\Exception To re-throw \PDOException.
  */
 public function query($sql, $bind = array())
 {
     if (empty($bind) && $sql instanceof Select) {
         $bind = $sql->getBind();
     }
     if (is_array($bind)) {
         foreach ($bind as $name => $value) {
             if (!is_int($name) && !preg_match('/^:/', $name)) {
                 $newName = ":{$name}";
                 unset($bind[$name]);
                 $bind[$newName] = $value;
             }
         }
     }
     try {
         return parent::query($sql, $bind);
     } catch (\PDOException $e) {
         throw new StatementException($e->getMessage(), $e->getCode(), $e);
     }
 }
Пример #4
0
 /**
  * Support method for fetching rows.
  *
  * @param  Select $select  query options.
  * @return array An array containing the row results in FETCH_ASSOC mode.
  */
 protected function _fetch(Select $select)
 {
     $stmt = $this->_db->query($select);
     $data = $stmt->fetchAll(Database::FETCH_ASSOC);
     return $data;
 }