Go to the documentation of this file.00001 <?php
00018 class axPDOStatementIterator extends IteratorIterator implements SeekableIterator, Countable {
00019
00024 protected $_statement;
00025
00030 protected $_count;
00031
00036 public function __construct (PDOStatement $statement) {
00037 parent::__construct($this->_statement = $statement);
00038 }
00039
00045 public function seek ($position) {
00046 if ($position > $this->count() || $position < $this->key())
00047 throw new OutOfBoundsException("Cannot seek to $position", 2008);
00048
00049 for ($i = $this->key(); $i < $position; $i++)
00050 $this->next();
00051 }
00052
00060 public function count () {
00061 if (!isset($this->_count))
00062 return $this->_count = $this->_statement->rowCount();
00063 return $this->_count;
00064 }
00065
00070 public function first () {
00071 $this->rewind();
00072 return $this->valid() ? $this->current() : null;
00073 }
00074
00079 public function last () {
00080 $this->seek($this->count());
00081 return $this->valid() ? $this->current() : null;
00082 }
00083 }