/** * 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); }
/** * 获取单条数据 * @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); }
function getLine() { if (!$this->_result) { return false; } return $this->_result->fetch(PDO::FETCH_ASSOC); }
protected function fetchRow() { $this->current = $this->pdoStatement->fetch(); if ($this->current) { $this->current->castInts(); $this->current->setNew(false); } }
/** * 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; }
/** * @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; } }
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']; }
/** * @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(); }
/** * 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); }
public function fetch() { $this->executeQuery(); $rs = $this->statement->fetch(PDO::FETCH_ASSOC); if ($rs === null) { return false; } else { return $rs; } }
/** * 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); } }
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); }
/** * {@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(); } }
/** * {@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; }
/** * 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); }
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; }
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; } }
public function each($fn, $className = null, $args = []) { $className !== null && $this->bindToClass($className, $args); while ($row = $this->statement->fetch()) { $fn($row); } }
/** * 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); }
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')); }
public static function executeFetchStatement(\PDOStatement $stmt) { if (!$stmt->execute()) { return null; } return $stmt->fetch(\PDO::FETCH_ASSOC); }
/** * 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; }
/** * 获取单条记录 * 由于该方法会造成安全问题,所以不建议使用。在必须使用的场合,需要程序人员对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; }
/** * 根据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; } }
/** * Получение объекта из запроса * @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; }
/** * @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; }