File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+ class PDOIterator implements Iterator {
3
+ private $ position = 0 ;
4
+ private $ pdo ;
5
+ private $ fetchMode ;
6
+ private $ nextResult ;
7
+
8
+ public function __construct (PDOStatement $ pdo , $ fetchMode = PDO ::FETCH_ASSOC ) {
9
+ $ this ->position = 0 ;
10
+ $ this ->pdo = $ pdo ;
11
+ $ this ->fetchMode = $ fetchMode ;
12
+ }
13
+
14
+ function rewind () {
15
+ $ this ->position = 0 ;
16
+ $ this ->pdo ->execute ();
17
+ }
18
+
19
+ function current () {
20
+ return $ this ->nextResult ;
21
+ }
22
+
23
+ function key () {
24
+ return $ this ->position ;
25
+ }
26
+
27
+ function next () {
28
+ ++$ this ->position ;
29
+ $ this ->nextResult = $ this ->pdo ->fetch ($ this ->fetchMode , PDO ::FETCH_ORI_NEXT );
30
+ }
31
+
32
+ function valid () {
33
+ $ invalid = $ this ->nextResult === false ;
34
+ if ($ invalid ) {
35
+ $ this ->pdo ->closeCursor ();
36
+ }
37
+ return !$ invalid ;
38
+ }
39
+ }
You can’t perform that action at this time.
0 commit comments