_reset(); } /** * Execute the statement and return the results. * * @param array|null $params list of values to be bound to query * @return bool true on success, false otherwise */ public function execute($params = null) { $this->_reset(); return parent::execute($params); } /** * {@inheritDoc} * * @param string $type The type to fetch. * @return array|false */ public function fetch($type = parent::FETCH_TYPE_NUM) { if ($this->_allFetched) { $row = ($this->_counter < $this->_count) ? $this->_records[$this->_counter++] : false; $row = ($row && $type === static::FETCH_TYPE_NUM) ? array_values($row) : $row; return $row; } $record = parent::fetch($type); if ($record === false) { $this->_allFetched = true; $this->_counter = $this->_count + 1; $this->_statement->closeCursor(); return false; } $this->_count++; return $this->_records[] = $record; } /** * {@inheritdoc} */ public function fetchAssoc() { return $this->fetch(static::FETCH_TYPE_ASSOC); } /** * {@inheritDoc} * * @param string $type The type to fetch. * @return array */ public function fetchAll($type = parent::FETCH_TYPE_NUM) { if ($this->_allFetched) { return $this->_records; } $this->_records = parent::fetchAll($type); $this->_count = count($this->_records); $this->_allFetched = true; $this->_statement->closeCursor(); return $this->_records; } /** * {@inheritDoc} */ public function rowCount() { if (!$this->_allFetched) { $counter = $this->_counter; while ($this->fetch(static::FETCH_TYPE_ASSOC)) { } $this->_counter = $counter; } return $this->_count; } /** * Rewind the _counter property * * @return void */ public function rewind() { $this->_counter = 0; } /** * Reset all properties * * @return void */ protected function _reset() { $this->_count = $this->_counter = 0; $this->_records = []; $this->_allFetched = false; } }