Source code raw phps
<?php
define('DB_FETCH_ROW', 2);
define('DB_FETCH_ASSOC',1);
define('DB_FETCH_BOTH', 3);
require_once 'libraries/class.BaseArray.php';
abstract class DB_Common_Results implements Iterator, ArrayAccess{
protected $_resource;
protected $_numRows;
protected $_results = array();
protected $_counter = 0;
protected $_cursor = 0;
public function numRows()
{
return $this->_numRows;
}
abstract public function __construct($resource);
abstract public function doFetch($fetch_mode = DB_FETCH_ASSOC);
public function fetch($fetch_mode = DB_FETCH_ASSOC, $num = null)
{
if (is_null($num)) {
$this->_results[$this->_counter] = $this->doFetch($fetch_mode);
return $this->_results[$this->_counter++];
} else if ($num < $this->_counter) {
return $this->_results[$num];
} else {
$result = true;
while ($this->_counter <= $num && $result) {
$result = $this->doFetch($fetch_mode);
$this->_results[$this->_counter] = $result;
$this->_counter++;
}
return $this->_results[$num];
}
}
// Array behavior
public function offsetSet($key, $value)
{
return false;
}
public function offsetGet($key)
{
return $this->fetch(DB_FETCH_ASSOC, $key);
}
public function offsetUnset($key)
{
return false;
}
public function offsetExists($offset)
{
return ($offset >= 0 && $offset < $this->_numRows);
}
// Iterator behavior
public function rewind() {
$this->_cursor = 0;
}
public function current() {
return $this->fetch(DB_FETCH_ASSOC, $this->_cursor);
}
public function key() {
return $this->_cursor;
}
public function next() {
return $this->fetch(DB_FETCH_ASSOC, $this->_cursor++);
}
public function valid() {
return ($this->_cursor < $this->numRows());
}
}
Comments
There is currently no comment here.