2006-06-04 23:06:33 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2007-04-11 18:30:30 +00:00
|
|
|
* This file is part of the "dibi" project (http://dibi.texy.info/)
|
2006-06-04 23:06:33 +00:00
|
|
|
*
|
2007-06-24 23:49:57 +00:00
|
|
|
* @author David Grudl
|
|
|
|
* @copyright Copyright (c) 2005-2007 David Grudl aka -dgx- (http://www.dgx.cz)
|
|
|
|
* @license New BSD License
|
|
|
|
* @version $Revision$ $Date$
|
|
|
|
* @category Database
|
|
|
|
* @package Dibi
|
2006-06-04 23:06:33 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
// security - include dibi.php, not this file
|
2007-05-13 18:32:03 +00:00
|
|
|
if (!class_exists('dibi', FALSE)) die();
|
2006-06-04 23:06:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// PHP < 5.1 compatibility
|
|
|
|
if (!interface_exists('Countable', false)) {
|
|
|
|
interface Countable
|
|
|
|
{
|
|
|
|
function count();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* dibi result-set abstract class
|
|
|
|
*
|
|
|
|
* <code>
|
|
|
|
* $result = dibi::query('SELECT * FROM [table]');
|
|
|
|
* $value = $result->fetchSingle();
|
|
|
|
* $all = $result->fetchAll();
|
2007-01-08 00:55:11 +00:00
|
|
|
* $assoc = $result->fetchAssoc('id');
|
|
|
|
* $assoc = $result->fetchAssoc('active', 'id');
|
2006-06-04 23:06:33 +00:00
|
|
|
* unset($result);
|
|
|
|
* </code>
|
|
|
|
*/
|
|
|
|
abstract class DibiResult implements IteratorAggregate, Countable
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Describes columns types
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $convert;
|
|
|
|
|
2007-03-27 23:12:36 +00:00
|
|
|
/**
|
|
|
|
* Describes columns types
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $meta;
|
|
|
|
|
2006-06-04 23:06:33 +00:00
|
|
|
|
2007-06-25 23:47:05 +00:00
|
|
|
private static $types = array(
|
2007-01-08 00:55:11 +00:00
|
|
|
dibi::FIELD_TEXT => 'string',
|
|
|
|
dibi::FIELD_BINARY => 'string',
|
|
|
|
dibi::FIELD_BOOL => 'bool',
|
|
|
|
dibi::FIELD_INTEGER => 'int',
|
|
|
|
dibi::FIELD_FLOAT => 'float',
|
|
|
|
dibi::FIELD_COUNTER => 'int',
|
|
|
|
);
|
|
|
|
|
2006-06-04 23:06:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Moves cursor position without fetching row
|
|
|
|
* @param int the 0-based cursor pos to seek to
|
|
|
|
* @return boolean TRUE on success, FALSE if unable to seek to specified record
|
|
|
|
*/
|
|
|
|
abstract public function seek($row);
|
|
|
|
|
2007-03-27 23:12:36 +00:00
|
|
|
|
|
|
|
|
2006-06-04 23:06:33 +00:00
|
|
|
/**
|
|
|
|
* Returns the number of rows in a result set
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
abstract public function rowCount();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Frees the resources allocated for this result set
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
abstract protected function free();
|
|
|
|
|
2007-03-27 23:12:36 +00:00
|
|
|
|
|
|
|
|
2006-06-04 23:06:33 +00:00
|
|
|
/**
|
|
|
|
* Fetches the row at current position and moves the internal cursor to the next position
|
|
|
|
* internal usage only
|
2007-06-25 17:02:12 +00:00
|
|
|
* @return array|FALSE array on success, FALSE if no next record
|
2006-06-04 23:06:33 +00:00
|
|
|
*/
|
|
|
|
abstract protected function doFetch();
|
|
|
|
|
|
|
|
|
2007-03-27 23:12:36 +00:00
|
|
|
|
2006-06-04 23:06:33 +00:00
|
|
|
/**
|
|
|
|
* Fetches the row at current position, process optional type conversion
|
|
|
|
* and moves the internal cursor to the next position
|
2007-06-25 17:02:12 +00:00
|
|
|
* @return array|FALSE array on success, FALSE if no next record
|
2006-06-04 23:06:33 +00:00
|
|
|
*/
|
|
|
|
final public function fetch()
|
|
|
|
{
|
2007-06-25 17:02:12 +00:00
|
|
|
$row = $this->doFetch();
|
2007-08-23 17:12:58 +00:00
|
|
|
if (!is_array($row)) return FALSE;
|
2006-06-04 23:06:33 +00:00
|
|
|
|
|
|
|
// types-converting?
|
|
|
|
if ($t = $this->convert) { // little speed-up
|
2007-06-25 17:02:12 +00:00
|
|
|
foreach ($row as $key => $value) {
|
2007-08-23 17:12:58 +00:00
|
|
|
if (isset($t[$key])) {
|
2007-06-25 17:02:12 +00:00
|
|
|
$row[$key] = $this->convert($value, $t[$key]);
|
2007-08-23 17:12:58 +00:00
|
|
|
}
|
2006-06-04 23:06:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-25 17:02:12 +00:00
|
|
|
return $row;
|
2006-06-04 23:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Like fetch(), but returns only first field
|
|
|
|
* @return mixed value on success, FALSE if no next record
|
|
|
|
*/
|
|
|
|
final function fetchSingle()
|
|
|
|
{
|
2007-06-25 17:02:12 +00:00
|
|
|
$row = $this->doFetch();
|
2007-08-23 17:12:58 +00:00
|
|
|
if (!is_array($row)) return FALSE;
|
2006-06-04 23:06:33 +00:00
|
|
|
|
|
|
|
// types-converting?
|
|
|
|
if ($t = $this->convert) { // little speed-up
|
2007-06-25 17:02:12 +00:00
|
|
|
$value = reset($row);
|
|
|
|
$key = key($row);
|
2006-06-04 23:06:33 +00:00
|
|
|
return isset($t[$key])
|
|
|
|
? $this->convert($value, $t[$key])
|
|
|
|
: $value;
|
|
|
|
}
|
|
|
|
|
2007-06-25 17:02:12 +00:00
|
|
|
return reset($row);
|
2006-06-04 23:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2007-02-05 05:14:48 +00:00
|
|
|
* Fetches all records from table.
|
2006-06-04 23:06:33 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
final function fetchAll()
|
|
|
|
{
|
|
|
|
@$this->seek(0);
|
2007-06-25 17:02:12 +00:00
|
|
|
$row = $this->fetch();
|
2007-08-23 17:12:58 +00:00
|
|
|
if (!$row) return array(); // empty resultset
|
2006-06-04 23:06:33 +00:00
|
|
|
|
2007-06-25 17:02:12 +00:00
|
|
|
$data = array();
|
|
|
|
if (count($row) === 1) {
|
|
|
|
$key = key($row);
|
2006-06-04 23:06:33 +00:00
|
|
|
do {
|
2007-06-25 17:02:12 +00:00
|
|
|
$data[] = $row[$key];
|
|
|
|
} while ($row = $this->fetch());
|
2006-06-04 23:06:33 +00:00
|
|
|
|
2007-01-08 00:55:11 +00:00
|
|
|
} else {
|
|
|
|
|
|
|
|
do {
|
2007-06-25 17:02:12 +00:00
|
|
|
$data[] = $row;
|
|
|
|
} while ($row = $this->fetch());
|
2006-06-04 23:06:33 +00:00
|
|
|
}
|
|
|
|
|
2007-06-25 17:02:12 +00:00
|
|
|
return $data;
|
2007-01-08 00:55:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2007-02-05 05:14:48 +00:00
|
|
|
* Fetches all records from table and returns associative tree
|
|
|
|
* Associative descriptor: assoc1,*,assoc2,#,assco3
|
2007-06-25 17:02:12 +00:00
|
|
|
* builds a tree: $data[value1][index][value2]['assoc3'][value3] = {record}
|
2007-02-05 05:14:48 +00:00
|
|
|
*
|
|
|
|
* @param string associative descriptor
|
2007-01-08 00:55:11 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
2007-02-05 05:14:48 +00:00
|
|
|
final function fetchAssoc($assoc)
|
2007-01-08 00:55:11 +00:00
|
|
|
{
|
|
|
|
@$this->seek(0);
|
2007-06-25 17:02:12 +00:00
|
|
|
$row = $this->fetch();
|
|
|
|
if (!$row) return array(); // empty resultset
|
2007-01-08 00:55:11 +00:00
|
|
|
|
2007-06-25 17:02:12 +00:00
|
|
|
$data = NULL;
|
2007-02-05 05:14:48 +00:00
|
|
|
$assoc = explode(',', $assoc);
|
2007-02-02 03:51:43 +00:00
|
|
|
|
2007-02-05 05:14:48 +00:00
|
|
|
if (count($assoc) === 1) { // speed-up
|
|
|
|
$as = $assoc[0];
|
|
|
|
do {
|
2007-06-25 17:02:12 +00:00
|
|
|
$data[ $row[$as] ] = $row;
|
|
|
|
} while ($row = $this->fetch());
|
|
|
|
return $data;
|
2007-02-05 05:14:48 +00:00
|
|
|
}
|
2007-02-02 03:51:43 +00:00
|
|
|
|
2007-02-05 05:14:48 +00:00
|
|
|
$last = count($assoc) - 1;
|
|
|
|
if ($assoc[$last] === '#') unset($assoc[$last]);
|
2007-01-08 00:55:11 +00:00
|
|
|
|
2007-02-05 05:14:48 +00:00
|
|
|
// make associative tree
|
|
|
|
do {
|
2007-06-25 17:02:12 +00:00
|
|
|
$x = & $data;
|
2007-02-05 05:14:48 +00:00
|
|
|
|
|
|
|
// iterative deepening
|
|
|
|
foreach ($assoc as $i => $as) {
|
|
|
|
if ($as === '*') { // indexed-array node
|
|
|
|
$x = & $x[];
|
|
|
|
|
|
|
|
} elseif ($as === '#') { // "record" node
|
|
|
|
if ($x === NULL) {
|
2007-06-25 17:02:12 +00:00
|
|
|
$x = $row;
|
2007-02-05 05:14:48 +00:00
|
|
|
$x = & $x[ $assoc[$i+1] ];
|
|
|
|
$x = NULL; // prepare child node
|
|
|
|
} else {
|
|
|
|
$x = & $x[ $assoc[$i+1] ];
|
|
|
|
}
|
|
|
|
|
|
|
|
} else { // associative-array node
|
2007-06-25 17:02:12 +00:00
|
|
|
$x = & $x[ $row[ $as ] ];
|
2007-02-05 05:14:48 +00:00
|
|
|
}
|
2006-06-04 23:06:33 +00:00
|
|
|
}
|
|
|
|
|
2007-06-25 17:02:12 +00:00
|
|
|
if ($x === NULL) $x = $row; // build leaf
|
2006-06-04 23:06:33 +00:00
|
|
|
|
2007-06-25 17:02:12 +00:00
|
|
|
} while ($row = $this->fetch());
|
2006-06-04 23:06:33 +00:00
|
|
|
|
2007-02-05 05:14:48 +00:00
|
|
|
unset($x);
|
2007-06-25 17:02:12 +00:00
|
|
|
return $data;
|
2006-06-04 23:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-05 05:14:48 +00:00
|
|
|
|
2006-06-04 23:06:33 +00:00
|
|
|
/**
|
|
|
|
* Fetches all records from table like $key => $value pairs
|
2007-04-25 08:19:03 +00:00
|
|
|
* @param string associative key
|
|
|
|
* @param string value
|
2006-06-04 23:06:33 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
2007-08-09 03:31:34 +00:00
|
|
|
final function fetchPairs($key = NULL, $value = NULL)
|
2006-06-04 23:06:33 +00:00
|
|
|
{
|
|
|
|
@$this->seek(0);
|
2007-06-25 17:02:12 +00:00
|
|
|
$row = $this->fetch();
|
|
|
|
if (!$row) return array(); // empty resultset
|
2006-06-04 23:06:33 +00:00
|
|
|
|
2007-06-25 17:02:12 +00:00
|
|
|
$data = array();
|
2007-06-11 00:25:48 +00:00
|
|
|
|
2007-04-25 08:19:03 +00:00
|
|
|
if ($value === NULL) {
|
2007-06-11 00:25:48 +00:00
|
|
|
if ($key !== NULL) return FALSE; // error
|
|
|
|
|
|
|
|
// autodetect
|
2007-06-25 17:02:12 +00:00
|
|
|
if (count($row) < 2) return FALSE;
|
|
|
|
$tmp = array_keys($row);
|
2007-04-25 08:19:03 +00:00
|
|
|
$key = $tmp[0];
|
|
|
|
$value = $tmp[1];
|
2007-06-11 00:25:48 +00:00
|
|
|
|
2007-04-25 08:19:03 +00:00
|
|
|
} else {
|
2007-06-25 17:02:12 +00:00
|
|
|
if (!array_key_exists($value, $row)) return FALSE;
|
2007-06-11 00:25:48 +00:00
|
|
|
|
|
|
|
if ($key === NULL) { // autodetect
|
|
|
|
do {
|
2007-06-25 17:02:12 +00:00
|
|
|
$data[] = $row[$value];
|
|
|
|
} while ($row = $this->fetch());
|
|
|
|
return $data;
|
2007-06-11 00:25:48 +00:00
|
|
|
}
|
|
|
|
|
2007-06-25 17:02:12 +00:00
|
|
|
if (!array_key_exists($key, $row)) return FALSE;
|
2007-04-25 08:19:03 +00:00
|
|
|
}
|
|
|
|
|
2006-06-04 23:06:33 +00:00
|
|
|
do {
|
2007-06-25 17:02:12 +00:00
|
|
|
$data[ $row[$key] ] = $row[$value];
|
|
|
|
} while ($row = $this->fetch());
|
2006-06-04 23:06:33 +00:00
|
|
|
|
2007-06-25 17:02:12 +00:00
|
|
|
return $data;
|
2006-06-04 23:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Automatically frees the resources allocated for this result set
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __destruct()
|
|
|
|
{
|
|
|
|
@$this->free();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-08-09 03:31:34 +00:00
|
|
|
final public function setType($field, $type = NULL)
|
2006-06-04 23:06:33 +00:00
|
|
|
{
|
2007-08-23 17:12:58 +00:00
|
|
|
if ($field === TRUE) {
|
2006-06-04 23:06:33 +00:00
|
|
|
$this->detectTypes();
|
|
|
|
|
2007-08-23 17:12:58 +00:00
|
|
|
} elseif (is_array($field)) {
|
2006-06-04 23:06:33 +00:00
|
|
|
$this->convert = $field;
|
|
|
|
|
2007-08-23 17:12:58 +00:00
|
|
|
} else {
|
2006-06-04 23:06:33 +00:00
|
|
|
$this->convert[$field] = $type;
|
2007-08-23 17:12:58 +00:00
|
|
|
}
|
2006-06-04 23:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-27 23:12:36 +00:00
|
|
|
|
2006-06-04 23:06:33 +00:00
|
|
|
/** is this needed? */
|
2007-08-09 03:31:34 +00:00
|
|
|
final public function getType($field)
|
2006-06-04 23:06:33 +00:00
|
|
|
{
|
|
|
|
return isset($this->convert[$field]) ? $this->convert[$field] : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-27 23:12:36 +00:00
|
|
|
|
2007-08-09 03:31:34 +00:00
|
|
|
final public function convert($value, $type)
|
2006-06-04 23:06:33 +00:00
|
|
|
{
|
2007-08-23 17:12:58 +00:00
|
|
|
if ($value === NULL || $value === FALSE) {
|
2006-06-04 23:06:33 +00:00
|
|
|
return $value;
|
2007-08-23 17:12:58 +00:00
|
|
|
}
|
2006-06-04 23:06:33 +00:00
|
|
|
|
2007-03-27 23:12:36 +00:00
|
|
|
if (isset(self::$types[$type])) {
|
|
|
|
settype($value, self::$types[$type]);
|
2006-06-04 23:06:33 +00:00
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
|
2007-08-23 17:12:58 +00:00
|
|
|
if ($type === dibi::FIELD_DATE) {
|
2006-06-07 15:50:32 +00:00
|
|
|
return strtotime($value); // !!! not good
|
2007-08-23 17:12:58 +00:00
|
|
|
}
|
2006-06-04 23:06:33 +00:00
|
|
|
|
2007-08-23 17:12:58 +00:00
|
|
|
if ($type === dibi::FIELD_DATETIME) {
|
2006-06-07 15:50:32 +00:00
|
|
|
return strtotime($value); // !!! not good
|
2007-08-23 17:12:58 +00:00
|
|
|
}
|
2006-06-04 23:06:33 +00:00
|
|
|
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-27 23:12:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets an array of field names
|
|
|
|
* @return array
|
|
|
|
*/
|
2007-08-09 03:31:34 +00:00
|
|
|
final public function getFields()
|
2007-03-27 23:12:36 +00:00
|
|
|
{
|
|
|
|
// lazy init
|
2007-08-23 17:12:58 +00:00
|
|
|
if ($this->meta === NULL) {
|
|
|
|
$this->buildMeta();
|
|
|
|
}
|
2007-03-27 23:12:36 +00:00
|
|
|
return array_keys($this->meta);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets an array of meta informations about column
|
|
|
|
* @param string column name
|
|
|
|
* @return array
|
|
|
|
*/
|
2007-08-09 03:31:34 +00:00
|
|
|
final public function getMetaData($field)
|
2007-03-27 23:12:36 +00:00
|
|
|
{
|
|
|
|
// lazy init
|
2007-08-23 17:12:58 +00:00
|
|
|
if ($this->meta === NULL) {
|
|
|
|
$this->buildMeta();
|
|
|
|
}
|
2007-03-27 23:12:36 +00:00
|
|
|
return isset($this->meta[$field]) ? $this->meta[$field] : FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Acquires ....
|
|
|
|
* @return void
|
|
|
|
*/
|
2007-08-09 03:31:34 +00:00
|
|
|
final protected function detectTypes()
|
2007-03-27 23:12:36 +00:00
|
|
|
{
|
2007-08-23 17:12:58 +00:00
|
|
|
if ($this->meta === NULL) {
|
|
|
|
$this->buildMeta();
|
|
|
|
}
|
2007-03-27 23:12:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
abstract protected function buildMeta();
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-06-04 23:06:33 +00:00
|
|
|
/** these are the required IteratorAggregate functions */
|
2007-08-09 03:31:34 +00:00
|
|
|
final public function getIterator($offset = NULL, $count = NULL)
|
2006-06-04 23:06:33 +00:00
|
|
|
{
|
|
|
|
return new DibiResultIterator($this, $offset, $count);
|
|
|
|
}
|
|
|
|
/** end required IteratorAggregate functions */
|
|
|
|
|
|
|
|
|
2007-03-27 23:12:36 +00:00
|
|
|
|
2006-06-04 23:06:33 +00:00
|
|
|
/** these are the required Countable functions */
|
2007-08-09 03:31:34 +00:00
|
|
|
final public function count()
|
2006-06-04 23:06:33 +00:00
|
|
|
{
|
|
|
|
return $this->rowCount();
|
|
|
|
}
|
|
|
|
/** end required Countable functions */
|
|
|
|
|
2006-10-26 13:09:56 +00:00
|
|
|
|
2007-03-27 23:12:36 +00:00
|
|
|
|
2007-06-25 23:47:05 +00:00
|
|
|
/**#@+
|
2007-06-24 15:07:10 +00:00
|
|
|
* Access to undeclared property
|
2007-06-25 23:47:05 +00:00
|
|
|
* @throws Exception
|
2006-10-26 13:09:56 +00:00
|
|
|
*/
|
2007-08-27 22:38:14 +00:00
|
|
|
private function &__get($name) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$name"); }
|
2007-08-20 22:17:52 +00:00
|
|
|
private function __set($name, $value) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$name"); }
|
|
|
|
private function __unset($name) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$name"); }
|
2007-06-25 23:47:05 +00:00
|
|
|
/**#@-*/
|
2006-10-26 13:09:56 +00:00
|
|
|
|
2006-06-04 23:06:33 +00:00
|
|
|
} // class DibiResult
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Basic Result set iterator.
|
|
|
|
*
|
|
|
|
* This can be returned by DibiResult::getIterator() method or directly using foreach:
|
|
|
|
* <code>
|
|
|
|
* $result = dibi::query('SELECT * FROM table');
|
|
|
|
* foreach ($result as $fields) {
|
|
|
|
* print_r($fields);
|
|
|
|
* }
|
|
|
|
* unset($result);
|
|
|
|
* </code>
|
|
|
|
*
|
|
|
|
* Optionally you can specify offset and limit:
|
|
|
|
* <code>
|
|
|
|
* foreach ($result->getIterator(2, 3) as $fields) {
|
|
|
|
* print_r($fields);
|
|
|
|
* }
|
|
|
|
* </code>
|
|
|
|
*/
|
2007-08-09 03:31:34 +00:00
|
|
|
final class DibiResultIterator implements Iterator
|
2006-06-04 23:06:33 +00:00
|
|
|
{
|
|
|
|
private
|
|
|
|
$result,
|
|
|
|
$offset,
|
|
|
|
$count,
|
2007-06-25 17:02:12 +00:00
|
|
|
$row,
|
|
|
|
$pointer;
|
2006-06-04 23:06:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
public function __construct(DibiResult $result, $offset = NULL, $count = NULL)
|
|
|
|
{
|
|
|
|
$this->result = $result;
|
|
|
|
$this->offset = (int) $offset;
|
2006-06-04 23:09:53 +00:00
|
|
|
$this->count = $count === NULL ? 2147483647 /*PHP_INT_MAX till 5.0.5 */ : (int) $count;
|
2006-06-04 23:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-27 23:12:36 +00:00
|
|
|
|
2006-06-04 23:06:33 +00:00
|
|
|
/** these are the required Iterator functions */
|
|
|
|
public function rewind()
|
|
|
|
{
|
2007-06-25 17:02:12 +00:00
|
|
|
$this->pointer = 0;
|
2006-06-04 23:06:33 +00:00
|
|
|
@$this->result->seek($this->offset);
|
2007-06-25 17:02:12 +00:00
|
|
|
$this->row = $this->result->fetch();
|
2006-06-04 23:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-27 23:12:36 +00:00
|
|
|
|
2006-06-04 23:06:33 +00:00
|
|
|
public function key()
|
|
|
|
{
|
2007-06-25 17:02:12 +00:00
|
|
|
return $this->pointer;
|
2006-06-04 23:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-27 23:12:36 +00:00
|
|
|
|
2006-06-04 23:06:33 +00:00
|
|
|
public function current()
|
|
|
|
{
|
2007-06-25 17:02:12 +00:00
|
|
|
return $this->row;
|
2006-06-04 23:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-27 23:12:36 +00:00
|
|
|
|
2006-06-04 23:06:33 +00:00
|
|
|
public function next()
|
|
|
|
{
|
2007-06-25 17:02:12 +00:00
|
|
|
$this->row = $this->result->fetch();
|
|
|
|
$this->pointer++;
|
2006-06-04 23:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-27 23:12:36 +00:00
|
|
|
|
2006-06-04 23:06:33 +00:00
|
|
|
public function valid()
|
|
|
|
{
|
2007-06-25 17:02:12 +00:00
|
|
|
return is_array($this->row) && ($this->pointer < $this->count);
|
2006-06-04 23:06:33 +00:00
|
|
|
}
|
|
|
|
/** end required Iterator functions */
|
|
|
|
|
|
|
|
|
2006-10-26 13:09:56 +00:00
|
|
|
|
2006-06-04 23:06:33 +00:00
|
|
|
} // class DibiResultIterator
|