]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiDB/adodb/adodb-iterator.inc.php
extra_empty_lines
[SourceForge/phpwiki.git] / lib / WikiDB / adodb / adodb-iterator.inc.php
1 <?php
2
3 /*
4   V4.22 15 Apr 2004  (c) 2000-2004 John Lim (jlim@natsoft.com.my). All rights reserved.
5   Released under both BSD license and Lesser GPL library license.
6   Whenever there is any discrepancy between the two licenses,
7   the BSD license will take precedence.
8
9   Set tabs to 4.
10
11   PHP5 Iterator Class:
12
13           $rs = $db->Execute("select * from adoxyz");
14         foreach($rs as $k => $v) {
15             echo $k; print_r($v); echo "<br>";
16         }
17
18     Iterator code based on http://cvs.php.net/cvs.php/php-src/ext/spl/examples/cachingiterator.inc?login=2
19  */
20
21  class ADODB_Iterator implements Iterator {
22
23     private $rs;
24
25     function __construct($rs)
26     {
27         $this->rs = $rs;
28     }
29     function rewind()
30     {
31         $this->rs->MoveFirst();
32     }
33
34     function valid()
35     {
36         return !$this->rs->EOF;
37     }
38
39     function key()
40     {
41         return $this->rs->_currentRow;
42     }
43
44     function current()
45     {
46         return $this->rs->fields;
47     }
48
49     function next()
50     {
51         $this->rs->MoveNext();
52     }
53
54     function __call($func, $params)
55     {
56         return call_user_func_array(array($this->rs, $func), $params);
57     }
58
59     function __toString()
60     {
61         return 'ADODB Iterator';
62     }
63
64 }
65
66 class ADODB_BASE_RS implements IteratorAggregate {
67     function getIterator() {
68         return new ADODB_Iterator($this);
69     }
70 }
71
72 ?>