Пример #1
0
 /**
  * Prefetch data
  */
 protected function prefetch()
 {
     if (!$this->currentFetched) {
         $this->currentData = $this->statement->fetch();
         $this->currentFetched = true;
     }
 }
 /**
  * @inheritDoc
  */
 public function next()
 {
     $this->cursorOffset++;
     // Fetching one row, located at the given offset in the result set
     // (This is what PDO::FETCH_ORI_ABS is for).
     $this->currentRow = $this->statement->fetch(\PDO::FETCH_ASSOC, \PDO::FETCH_ORI_ABS, $this->cursorOffset);
 }
Пример #3
0
 /**
  * 获取单条数据
  * @param string $fetchStyle
  * @throws \HuiLib\Error\Exception
  * @return array|object
  */
 public function fetch()
 {
     if ($this->innerStatment == NULL) {
         throw new \HuiLib\Error\Exception('fetch必须先调用Query::query');
     }
     return $this->innerStatment->fetch($this->fetchStyle);
 }
Пример #4
0
 function getLine()
 {
     if (!$this->_result) {
         return false;
     }
     return $this->_result->fetch(PDO::FETCH_ASSOC);
 }
Пример #5
0
 protected function fetchRow()
 {
     $this->current = $this->pdoStatement->fetch();
     if ($this->current) {
         $this->current->castInts();
         $this->current->setNew(false);
     }
 }
Пример #6
0
 /**
  * Reads a piece of input data and advance to the next one.
  * Implementations must return null at the end of the input data set.
  * @return mixed
  */
 public function read()
 {
     if (!$this->ready) {
         $this->init();
     }
     $data = $this->stmnt->fetch(\PDO::FETCH_ASSOC);
     return $data ? $data : null;
 }
 /**
  * {@inheritdoc}
  */
 public function rewind()
 {
     if ($this->rewinded) {
         throw new InvalidMethodCallException('Cannot rewind a PDOStatement');
     }
     $this->current = $this->statement->fetch(\PDO::FETCH_ASSOC);
     $this->rewinded = true;
 }
Пример #8
0
 /** * @inheritDoc */
 public function next()
 {
     $this->key++;
     $this->result = $this->pdoStatement->fetch(\PDO::FETCH_OBJ, \PDO::FETCH_ORI_ABS, $this->key);
     if (false === $this->result) {
         $this->valid = false;
         return null;
     }
 }
Пример #9
0
 private function getDruaplNodeIdByWpPostId($wpPostId)
 {
     $this->getDruaplNodeIdByWpPostIdStatement->execute(array(':wp_post_id' => $wpPostId));
     $result = $this->getDruaplNodeIdByWpPostIdStatement->fetch(PDO::FETCH_ASSOC);
     if (!$result['nid']) {
         throw new Exception('No WP post ID: ' . $wpPostId);
     }
     return $result['nid'];
 }
Пример #10
0
 /**
  * @inheritDoc
  */
 public function next()
 {
     $this->key++;
     $this->result = $this->pdoStatement->fetch(PDO::FETCH_OBJ, PDO::FETCH_ORI_ABS, $this->key);
     if ($this->result === FALSE) {
         $this->valid = FALSE;
         return NULL;
     }
 }
 /**
  * <b>O parametro deve ser um array atribuitivo apenas com Id da tabela</b>
  * 
  * @param array $Dados
  * @return array
  */
 public function find(array $Dados)
 {
     $Condicao = array_keys($Dados)[0];
     $Id = "{$Condicao} = :{$Condicao}";
     $sql = "SELECT * FROM {$this->Table} WHERE {$Id}";
     $this->Stmt = Conn::prepare($sql);
     $this->Stmt->execute($Dados);
     return $this->Stmt->fetch();
 }
Пример #12
0
 /**
  * Fetch next result
  * 
  * @param boolean|string $object Fetch as object
  * @return \stdClass
  */
 public function next($object = TRUE)
 {
     if ($object) {
         if ($object === TRUE) {
             return $this->stmt->fetchObject();
         }
         return $this->stmt->fetchObject($object);
     }
     return $this->stmt->fetch(\PDO::FETCH_ASSOC);
 }
Пример #13
0
 public function fetch()
 {
     $this->executeQuery();
     $rs = $this->statement->fetch(PDO::FETCH_ASSOC);
     if ($rs === null) {
         return false;
     } else {
         return $rs;
     }
 }
Пример #14
0
 /**
  * Advances the curesor in the statement
  * Closes the cursor if the end of the statement is reached
  */
 public function next()
 {
     $this->currentRow = $this->stmt->fetch(PDO::FETCH_NUM);
     $this->currentKey++;
     $this->isValid = (bool) $this->currentRow;
     if (!$this->isValid) {
         $this->closeCursor();
         if ($this->enableInstancePoolingOnFinish) {
             Propel::enableInstancePooling();
         }
     }
 }
 public function next()
 {
     $this->current = null;
     if (($restore = $this->statement->fetch(\PDO::FETCH_ASSOC)) !== false) {
         $this->current = clone $this->storable;
         $this->current->schema()->validate($restore);
         if (isset($restore['guid'])) {
             $this->current->guid($restore['guid']);
             $this->storage->register($this->current);
         }
         $this->current->restore($restore);
     }
 }
Пример #16
0
 public function fetch($fetchStyle = null, $all = true)
 {
     if (is_null($this->query)) {
         throw new \Exception('Cannot invoke fetch. Try using query or prepare/execute before fetch.');
     }
     if (is_null($fetchStyle)) {
         $fetchStyle = \PDO::FETCH_OBJ;
     }
     if ($all === true) {
         return $this->query->fetchAll($fetchStyle);
     }
     return $this->query->fetch($fetchStyle);
 }
Пример #17
0
 /**
  * {@inheritdoc}
  */
 public function getFields()
 {
     if ($this->statement->execute()) {
         // Statement executed successfully
         // Grab the first row to find keys
         $row = $this->statement->fetch(\PDO::FETCH_ASSOC);
         // Return field keys, or empty array no rows remain
         return array_keys($row ? $row : array());
     } else {
         // If the statement errors return empty
         return array();
     }
 }
Пример #18
0
 /**
  * {@inheritDoc}
  */
 protected function realFetchRow($rowCount)
 {
     $result = [];
     $count = 0;
     while ($count++ < $rowCount) {
         $row = $this->statement->fetch(\PDO::FETCH_ASSOC);
         if (false === $row) {
             break;
         }
         $result[] = $row;
     }
     return $result;
 }
Пример #19
0
 /**
  * Fetch row.
  *
  * @param int $fetchStyle
  *
  * @return mixed
  */
 public function fetchRow($fetchStyle = \PDO::FETCH_BOTH)
 {
     // Converting MYSQL(I) to PDO constants
     // needed as all old Modules call this whith mysqli parameters
     switch ($fetchStyle) {
         case MYSQLI_ASSOC:
             $this->fetchStyle = \PDO::FETCH_ASSOC;
             break;
         case MYSQLI_BOTH:
             $this->fetchStyle = \PDO::FETCH_BOTH;
         default:
             $this->fetchStyle = $fetchStyle;
     }
     return $this->statement->fetch($this->fetchStyle);
 }
Пример #20
0
 public function fetchRowAssoc($escape = true)
 {
     $data = $this->_statement->fetch(\PDO::FETCH_ASSOC);
     if ($data === false) {
         return false;
     }
     if ($escape) {
         $escaped = array();
         foreach ($data as $key => $value) {
             $escaped[$key] = htmlentities($value);
         }
         return $escaped;
     }
     return $data;
 }
Пример #21
0
 public function query($sql, $noexcept = false, $params = array())
 {
     if (!$noexcept) {
         $this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
         $this->connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
     }
     $this->statement = $this->connection->prepare($sql);
     $result = false;
     $time_start = microtime(true);
     try {
         if ($this->statement && $this->statement->execute($params)) {
             $data = array();
             if ($this->statement->columnCount()) {
                 while ($row = $this->statement->fetch(PDO::FETCH_ASSOC)) {
                     $data[] = $row;
                 }
                 $result = new stdClass();
                 $result->row = isset($data[0]) ? $data[0] : array();
                 $result->rows = $data;
                 $result->num_rows = $this->statement->rowCount();
             }
         }
     } catch (PDOException $e) {
         $this->error = 'SQL Error: ' . $e->getMessage() . '<br />Error No: ' . $e->getCode() . '<br />SQL:' . $sql;
         if ($noexcept) {
             return false;
         } else {
             throw new AException(AC_ERR_MYSQL, $this->error);
         }
     }
     $time_exec = microtime(true) - $time_start;
     // to avoid debug class init while setting was not yet loaded
     if ($this->registry->get('config')) {
         if ($this->registry->get('config')->has('config_debug')) {
             $backtrace = debug_backtrace();
             ADebug::set_query($sql, $time_exec, $backtrace[2]);
         }
     }
     if ($result) {
         return $result;
     } else {
         $result = new stdClass();
         $result->row = array();
         $result->rows = array();
         $result->num_rows = 0;
         return $result;
     }
 }
Пример #22
0
 public function each($fn, $className = null, $args = [])
 {
     $className !== null && $this->bindToClass($className, $args);
     while ($row = $this->statement->fetch()) {
         $fn($row);
     }
 }
Пример #23
0
 /**
  * Fetch a result as an object of a class extending
  * wResults. Those class should allow their objects
  * to be saved back to the DB.
  *
  * @param string $className
  * @return wResultObjects
  */
 public function fetchObjectOfClass($className)
 {
     $table = $this->_prepareFetchObject($className);
     $instance = new $className();
     $this->setFetchMode(\PDO::FETCH_INTO, $instance);
     return parent::fetch(\PDO::FETCH_INTO);
 }
Пример #24
0
 public function fetch($class = null)
 {
     if (!$this->result) {
         throw new Exception('Can\'t fetch result if no query!');
     }
     return $class === false ? $this->result->fetch(PDO::FETCH_ASSOC) : $this->result->fetchObject($class ?: self::config('fetch'));
 }
Пример #25
0
 public static function executeFetchStatement(\PDOStatement $stmt)
 {
     if (!$stmt->execute()) {
         return null;
     }
     return $stmt->fetch(\PDO::FETCH_ASSOC);
 }
Пример #26
0
 /**
  * Fetches the next row from the result set in memory (i.e., the one
  * that was created after running query()).
  *
  * @param string $fetch_style
  *            Controls how the rows will be returned.
  * @param obj $obj
  *            The object to be fetched into if
  *            $fetch_style is set to 'into'.
  * @return mixed
  */
 public function fetch($fetch_style = null, $obj = null)
 {
     $this->setFetchMode($fetch_style, $obj);
     $row = $this->statement->fetch();
     $this->statement->closeCursor();
     return $row;
 }
Пример #27
0
 /**
  * 获取单条记录
  * 由于该方法会造成安全问题,所以不建议使用。在必须使用的场合,需要程序人员对sql语句做严格验证
  * @param string $sql 预处理执行的sql
  * @param array $data 符合pdo预处理模式键值对
  * @return array
  * @deprecated since version 108
  */
 public function fetchRow($sql, $data = null)
 {
     $this->execute($sql, $data);
     $data = $this->stmt instanceof \PDOStatement ? $this->stmt->fetch() : FALSE;
     $this->stmt = null;
     return $data;
 }
Пример #28
0
 /**
  * 根据prepare类函数中的参数个数,传入$params
  * @param array $params 如array(':Avalue'=>'10', ':Bvalue'=>'yellow');
  * @param string $fetchRows 默认All时获取所有的,One则只获取一条
  * @param string $fetchType 默认array获得字段索引数组,row获得以数字为索引数组,both获得array和row,obj获得一个对象,col获取列则必须传入colIndex,如果$fetchRows和$fetchType都为空,则返回PDOStatement对象
  * @return \PDOStatement “注意此对象可能会被修改,所以不要写类似保存后在另外的地方使用的方法”
  */
 public function selectPrepared($params = array(), $fetchRows = 'All', $fetchType = 'array', $colIndex = 0)
 {
     $result = $this->execute($params);
     if ($result) {
         if ($fetchType == 'row') {
             $fetched = \PDO::FETCH_NUM;
         } elseif ($fetchType == 'obj') {
             $fetched = \PDO::FETCH_FETCH_CLASS;
         } elseif ($fetchType == '') {
             $fetched = \PDO::FETCH_BOTH;
         } elseif ($fetchType == 'col') {
             $fetched = \PDO::FETCH_COLUMN;
         } else {
             $fetched = \PDO::FETCH_ASSOC;
         }
         if ($fetchRows == 'All' || $fetchRows == 'all') {
             if ($fetchType == 'col') {
                 return $this->pdoStatement->fetchAll($fetched, $colIndex);
             } else {
                 return $this->pdoStatement->fetchAll($fetched);
             }
         } elseif ($fetchRows == 'One' || $fetchRows == 'one') {
             if ($fetchType == 'col') {
                 return $this->pdoStatement->fetch($fetched, $colIndex);
             } else {
                 return $this->pdoStatement->fetch($fetched);
             }
         }
         return $this->pdoStatement;
     } else {
         return FALSE;
     }
 }
Пример #29
0
 /**
  * Получение объекта из запроса
  * @return Item
  */
 public function fetchObject(\PDOStatement $statement)
 {
     $statement->setFetchMode(\PDO::FETCH_CLASS | \PDO::FETCH_PROPS_LATE, $this->getItemClass(), array($this->getManager(), $this->getTable(), false));
     /** @var Item $obj */
     $obj = $statement->fetch();
     return $obj;
 }
Пример #30
0
 /**
  * @param Nome do campo Indice $FildName
  * 
  * @return Ultimo Id do Banco
  */
 public function MaxFild($FildName)
 {
     $this->Termos = "SELECT MAX({$FildName}) as 'id' FROM {$this->Table}";
     $this->Busca(null, true);
     $this->Result = $this->Stmt->fetch()->id;
     return $this->Result;
 }