1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115:
<?php
class PDOSelectQueryResult extends AbstractSelectQueryResult
{
private $statement = null;
private $fetch_mode = null;
private $iterator = null;
private $is_disposed = false;
public function __construct($query, array $parameters, PDOStatement $statement, $fetch_mode = self::FETCH_ASSOC)
{
$this->statement = $statement;
$this->fetch_mode = $fetch_mode;
parent::__construct($query, $parameters);
}
public function __destruct()
{
$this->dispose();
}
public function set_fetch_mode($fetch_mode)
{
$this->fetch_mode = $fetch_mode;
}
public function get_rows_count()
{
return $this->statement->rowCount();
}
public function rewind()
{
if ($this->iterator === null)
{
$pdo_fetch_mode = PDO::FETCH_ASSOC;
switch ($this->fetch_mode)
{
case self::FETCH_NUM:
$pdo_fetch_mode = PDO::FETCH_NUM;
break;
case self::FETCH_ASSOC:
default:
$pdo_fetch_mode = PDO::FETCH_ASSOC;
break;
}
$this->iterator = new ArrayIterator($this->statement->fetchAll($pdo_fetch_mode));
}
$this->iterator->rewind();
}
public function valid()
{
if ($this->iterator === null)
{
$this->rewind();
}
return $this->iterator->valid();
}
public function current()
{
return $this->iterator->current();
}
public function key()
{
return $this->iterator->key();
}
public function next()
{
$this->iterator->next();
}
public function dispose()
{
if (!$this->is_disposed)
{
$this->statement->closeCursor();
$this->is_disposed = true;
}
}
protected function needs_rewind()
{
return $this->iterator === null;
}
}
?>