ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
Iterator.php
Go to the documentation of this file.
1<?php
2// +----------------------------------------------------------------------+
3// | PHP version 5 |
4// +----------------------------------------------------------------------+
5// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, |
6// | Stig. S. Bakken, Lukas Smith |
7// | All rights reserved. |
8// +----------------------------------------------------------------------+
9// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
10// | API as well as database abstraction for PHP applications. |
11// | This LICENSE is in the BSD license style. |
12// | |
13// | Redistribution and use in source and binary forms, with or without |
14// | modification, are permitted provided that the following conditions |
15// | are met: |
16// | |
17// | Redistributions of source code must retain the above copyright |
18// | notice, this list of conditions and the following disclaimer. |
19// | |
20// | Redistributions in binary form must reproduce the above copyright |
21// | notice, this list of conditions and the following disclaimer in the |
22// | documentation and/or other materials provided with the distribution. |
23// | |
24// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
25// | Lukas Smith nor the names of his contributors may be used to endorse |
26// | or promote products derived from this software without specific prior|
27// | written permission. |
28// | |
29// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
30// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
31// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
32// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
33// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
34// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
35// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
36// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
37// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
38// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
39// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
40// | POSSIBILITY OF SUCH DAMAGE. |
41// +----------------------------------------------------------------------+
42// | Author: Lukas Smith <smith@pooteeweet.org> |
43// +----------------------------------------------------------------------+
44//
45// $Id: Iterator.php,v 1.22 2006/05/06 14:03:41 lsmith Exp $
46
54class MDB2_Iterator implements Iterator
55{
56 protected $fetchmode;
57 protected $result;
58 protected $row;
59
60 // {{{ constructor
61
66 {
67 $this->result = $result;
68 $this->fetchmode = $fetchmode;
69 }
70 // }}}
71
72 // {{{ seek()
73
82 public function seek($rownum)
83 {
84 $this->row = null;
85 if ($this->result) {
86 $this->result->seek($rownum);
87 }
88 }
89 // }}}
90
91 // {{{ next()
92
99 public function next()
100 {
101 $this->row = null;
102 }
103 // }}}
104
105 // {{{ current()
106
113 public function current()
114 {
115 if (is_null($this->row)) {
116 $row = $this->result->fetchRow($this->fetchmode);
117 if (PEAR::isError($row)) {
118 $row = false;
119 }
120 $this->row = $row;
121 }
122 return $this->row;
123 }
124 // }}}
125
126 // {{{ valid()
127
134 public function valid()
135 {
136 return (bool)$this->current();
137 }
138 // }}}
139
140 // {{{ free()
141
148 public function free()
149 {
150 if ($this->result) {
151 return $this->result->free();
152 }
153 $this->result = false;
154 $this->row = null;
155 return false;
156 }
157 // }}}
158
159 // {{{ key()
160
167 public function key()
168 {
169 if ($this->result) {
170 return $this->result->rowCount();
171 }
172 return false;
173 }
174 // }}}
175
176 // {{{ rewind()
177
184 public function rewind()
185 {
186 }
187 // }}}
188
189 // {{{ destructor
190
194 public function __destruct()
195 {
196 $this->free();
197 }
198 // }}}
199}
200
209{
210 // {{{ valid()
211
218 public function valid()
219 {
220 if ($this->result) {
221 return $this->result->valid();
222 }
223 return false;
224 }
225 // }}}
226
227 // {{{count()
228
235 public function count()
236 {
237 if ($this->result) {
238 return $this->result->numRows();
239 }
240 return false;
241 }
242 // }}}
243
244 // {{{ rewind()
245
252 public function rewind()
253 {
254 $this->seek(0);
255 }
256 // }}}
257}
258
259?>
const MDB2_FETCHMODE_DEFAULT
This is a special constant that tells MDB2 the user hasn't specified any particular get mode,...
Definition: MDB2.php:119
valid()
Check if the end of the result set has been reached.
Definition: Iterator.php:218
rewind()
Seek to the first row in a result set.
Definition: Iterator.php:252
count()
Returns the number of rows in a result object.
Definition: Iterator.php:235
key()
Returns the row number.
Definition: Iterator.php:167
rewind()
Seek to the first row in a result set.
Definition: Iterator.php:184
next()
Fetch next row of data.
Definition: Iterator.php:99
valid()
Check if the end of the result set has been reached.
Definition: Iterator.php:134
free()
Free the internal resources associated with result.
Definition: Iterator.php:148
seek($rownum)
Seek forward to a specific row in a result set.
Definition: Iterator.php:82
__destruct()
Destructor.
Definition: Iterator.php:194
__construct($result, $fetchmode=MDB2_FETCHMODE_DEFAULT)
Constructor.
Definition: Iterator.php:65
current()
return a row of data
Definition: Iterator.php:113
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:279