|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Class DbMysqliResultIterator |
|
5
|
|
|
*/ |
|
6
|
|
|
class DbMysqliResultIterator extends DbRowIterator { |
|
7
|
|
|
/** |
|
8
|
|
|
* @var MySQLi_Result $Result |
|
9
|
|
|
*/ |
|
10
|
|
|
protected $Result; |
|
11
|
|
|
/** |
|
12
|
|
|
* @var int |
|
13
|
|
|
*/ |
|
14
|
|
|
protected $fetchMode; |
|
15
|
|
|
/** |
|
16
|
|
|
* @var int |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $position; |
|
19
|
|
|
/** |
|
20
|
|
|
* @var array |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $currentRow; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Constructor |
|
26
|
|
|
* |
|
27
|
|
|
* @param MySQLi_Result $Result |
|
28
|
|
|
* @param int $fetchMode constant (MYSQLI_ASSOC, MYSQLI_NUM, MYSQLI_BOTH) |
|
29
|
|
|
*/ |
|
30
|
|
|
public function __construct($Result, $fetchMode = MYSQLI_ASSOC) { |
|
31
|
|
|
$this->Result = $Result; |
|
32
|
|
|
$this->fetchMode = $fetchMode; |
|
33
|
|
|
|
|
34
|
|
|
$this->position = 0; |
|
35
|
|
|
// prefetch the current row |
|
36
|
|
|
// note that this advances the Results internal pointer. |
|
37
|
|
|
$this->currentRow = $this->Result->fetch_array($this->fetchMode); |
|
|
|
|
|
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Destructor |
|
42
|
|
|
* Frees the Result object |
|
43
|
|
|
*/ |
|
44
|
|
|
public function __destruct() { |
|
45
|
|
|
$this->Result->free(); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Return the current element |
|
51
|
|
|
* Returns the row that matches the current position |
|
52
|
|
|
* @link http://php.net/manual/en/iterator.current.php |
|
53
|
|
|
* @return mixed Can return any type. |
|
54
|
|
|
* @since 5.0.0 |
|
55
|
|
|
*/ |
|
56
|
|
|
public function current() { |
|
57
|
|
|
return $this->currentRow; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Move forward to next element |
|
62
|
|
|
* Moves the internal pointer one step forward |
|
63
|
|
|
* @link http://php.net/manual/en/iterator.next.php |
|
64
|
|
|
* @return void Any returned value is ignored. |
|
65
|
|
|
* @since 5.0.0 |
|
66
|
|
|
*/ |
|
67
|
|
|
public function next() { |
|
68
|
|
|
// prefetch the current row |
|
69
|
|
|
$this->currentRow = $this->Result->fetch_array($this->fetchMode); |
|
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
// and increment internal pointer |
|
72
|
|
|
++$this->position; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Return the key of the current element - the current position |
|
77
|
|
|
* @link http://php.net/manual/en/iterator.key.php |
|
78
|
|
|
* return mixed scalar on success, or null on failure. |
|
79
|
|
|
* @return int |
|
80
|
|
|
* @since 5.0.0 |
|
81
|
|
|
*/ |
|
82
|
|
|
public function key() { |
|
83
|
|
|
return $this->position; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Checks if current position is valid |
|
88
|
|
|
* Returns true if the current position is valid, false otherwise. |
|
89
|
|
|
* @link http://php.net/manual/en/iterator.valid.php |
|
90
|
|
|
* @return boolean The return value will be casted to boolean and then evaluated. |
|
91
|
|
|
* Returns true on success or false on failure. |
|
92
|
|
|
* @since 5.0.0 |
|
93
|
|
|
*/ |
|
94
|
|
|
public function valid() { |
|
95
|
|
|
return $this->position < $this->Result->num_rows; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Rewind the Iterator to the first element |
|
100
|
|
|
* @link http://php.net/manual/en/iterator.rewind.php |
|
101
|
|
|
* @return void Any returned value is ignored. |
|
102
|
|
|
* @since 5.0.0 |
|
103
|
|
|
*/ |
|
104
|
|
|
public function rewind() { |
|
105
|
|
|
// data_seek moves the Results internal pointer |
|
106
|
|
|
$this->Result->data_seek($this->position = 0); |
|
107
|
|
|
|
|
108
|
|
|
// prefetch the current row |
|
109
|
|
|
// note that this advances the Results internal pointer. |
|
110
|
|
|
$this->currentRow = $this->Result->fetch_array($this->fetchMode); |
|
|
|
|
|
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
} |
|
114
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..