1 | <?php |
||
2 | |||
3 | namespace Foolz\SphinxQL\Drivers\Mysqli; |
||
4 | |||
5 | use Foolz\SphinxQL\Drivers\ResultSetAdapterInterface; |
||
6 | use Foolz\SphinxQL\Exception\ConnectionException; |
||
7 | use mysqli_result; |
||
8 | |||
9 | class ResultSetAdapter implements ResultSetAdapterInterface |
||
10 | { |
||
11 | /** |
||
12 | * @var Connection |
||
13 | */ |
||
14 | protected $connection; |
||
15 | |||
16 | /** |
||
17 | * @var mysqli_result|bool |
||
18 | */ |
||
19 | protected $result; |
||
20 | |||
21 | /** |
||
22 | * @var bool |
||
23 | */ |
||
24 | protected $valid = true; |
||
25 | |||
26 | /** |
||
27 | * @param Connection $connection |
||
28 | * @param mysqli_result|bool $result |
||
29 | */ |
||
30 | public function __construct(Connection $connection, $result) |
||
31 | { |
||
32 | $this->connection = $connection; |
||
33 | $this->result = $result; |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * @inheritdoc |
||
38 | * @throws ConnectionException |
||
39 | */ |
||
40 | public function getAffectedRows() |
||
41 | { |
||
42 | return $this->connection->getConnection()->affected_rows; |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
43 | } |
||
44 | |||
45 | /** |
||
46 | * @inheritdoc |
||
47 | */ |
||
48 | public function getNumRows() |
||
49 | { |
||
50 | return $this->result->num_rows; |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * @inheritdoc |
||
55 | */ |
||
56 | public function getFields() |
||
57 | { |
||
58 | return $this->result->fetch_fields(); |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * @inheritdoc |
||
63 | */ |
||
64 | public function isDml() |
||
65 | { |
||
66 | return !($this->result instanceof mysqli_result); |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * @inheritdoc |
||
71 | */ |
||
72 | public function store() |
||
73 | { |
||
74 | $this->result->data_seek(0); |
||
75 | |||
76 | return $this->result->fetch_all(MYSQLI_NUM); |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * @inheritdoc |
||
81 | */ |
||
82 | public function toRow($num) |
||
83 | { |
||
84 | $this->result->data_seek($num); |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * @inheritdoc |
||
89 | */ |
||
90 | public function freeResult() |
||
91 | { |
||
92 | $this->result->free_result(); |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * @inheritdoc |
||
97 | */ |
||
98 | public function rewind() |
||
99 | { |
||
100 | $this->valid = true; |
||
101 | $this->result->data_seek(0); |
||
102 | } |
||
103 | |||
104 | /** |
||
105 | * @inheritdoc |
||
106 | */ |
||
107 | public function valid() |
||
108 | { |
||
109 | return $this->valid; |
||
110 | } |
||
111 | |||
112 | /** |
||
113 | * @inheritdoc |
||
114 | */ |
||
115 | public function fetch($assoc = true) |
||
116 | { |
||
117 | if ($assoc) { |
||
118 | $row = $this->result->fetch_assoc(); |
||
119 | } else { |
||
120 | $row = $this->result->fetch_row(); |
||
121 | } |
||
122 | |||
123 | if (!$row) { |
||
124 | $this->valid = false; |
||
125 | } |
||
126 | |||
127 | return $row; |
||
128 | } |
||
129 | |||
130 | /** |
||
131 | * @inheritdoc |
||
132 | */ |
||
133 | public function fetchAll($assoc = true) |
||
134 | { |
||
135 | if ($assoc) { |
||
136 | $row = $this->result->fetch_all(MYSQLI_ASSOC); |
||
137 | } else { |
||
138 | $row = $this->result->fetch_all(MYSQLI_NUM); |
||
139 | } |
||
140 | |||
141 | if (empty($row)) { |
||
142 | $this->valid = false; |
||
143 | } |
||
144 | |||
145 | return $row; |
||
146 | } |
||
147 | } |
||
148 |