1 | <?php |
||
11 | class Database |
||
12 | { |
||
13 | /** |
||
14 | * @var array $options used when creating the PDO object |
||
15 | * @var PDO $pdo the PDO object |
||
16 | * @var PDOStatement $stmt the latest PDOStatement used |
||
17 | */ |
||
18 | protected $options; |
||
19 | private $pdo = null; |
||
20 | private $stmt = null; |
||
21 | |||
22 | |||
23 | |||
24 | /** |
||
25 | * Constructor creating a PDO object connecting to a choosen database. |
||
26 | * |
||
27 | * @param array $options containing details for connecting to the database. |
||
28 | */ |
||
29 | 8 | public function __construct($options = []) |
|
33 | |||
34 | |||
35 | |||
36 | /** |
||
37 | * Set options and connection details. |
||
38 | * |
||
39 | * @param array $options containing details for connecting to the database. |
||
40 | * |
||
41 | * @return void |
||
42 | */ |
||
43 | 8 | public function setOptions($options = []) |
|
58 | |||
59 | |||
60 | |||
61 | /** |
||
62 | * Connect to the database, allow being called multiple times |
||
63 | * but ignore when connection is already made. |
||
64 | * |
||
65 | * @return self |
||
66 | * |
||
67 | * @throws \Anax\Database\Exception |
||
68 | */ |
||
69 | 8 | public function connect() |
|
98 | |||
99 | |||
100 | |||
101 | /** |
||
102 | * Support arrays in params, extract array items and add to $params |
||
103 | * and insert ? for each entry in the array. |
||
104 | * |
||
105 | * @param string $query as the query to prepare. |
||
106 | * @param array $params the parameters that may contain arrays. |
||
107 | * |
||
108 | * @return array with query and params. |
||
109 | */ |
||
110 | 6 | private function expandParamArray($query, $params) |
|
137 | |||
138 | |||
139 | |||
140 | /** |
||
141 | * Execute a select-query with arguments and return the resultset. |
||
142 | * |
||
143 | * @param string $query the SQL statement |
||
144 | * @param array $params the params array |
||
145 | * |
||
146 | * @return array with resultset |
||
147 | */ |
||
148 | public function executeFetchAll($query, $params = []) |
||
153 | |||
154 | |||
155 | |||
156 | /** |
||
157 | * Execute a select-query with arguments and return the first row |
||
158 | * in the resultset. |
||
159 | * |
||
160 | * @param string $query the SQL statement |
||
161 | * @param array $params the params array |
||
162 | * |
||
163 | * @return array with resultset |
||
164 | */ |
||
165 | 1 | public function executeFetch($query, $params = []) |
|
170 | |||
171 | |||
172 | |||
173 | /** |
||
174 | * Execute a select-query with arguments and insert the results into |
||
175 | * a new object of the class. |
||
176 | * |
||
177 | * @param string $query the SQL statement |
||
178 | * @param array $params the params array |
||
179 | * @param string $class the class to create an object of and insert into |
||
180 | * |
||
181 | * @return array with resultset |
||
182 | */ |
||
183 | public function executeFetchClass($query, $params, $class) |
||
189 | |||
190 | |||
191 | |||
192 | /** |
||
193 | * Execute a select-query with arguments and insert the results into |
||
194 | * an existing object. |
||
195 | * |
||
196 | * @param string $query the SQL statement |
||
197 | * @param array $params the params array |
||
|
|||
198 | * @param string $object the existing object to insert into |
||
199 | * |
||
200 | * @return array with resultset |
||
201 | */ |
||
202 | public function executeFetchInto($query, $param, $object = null) |
||
212 | |||
213 | |||
214 | |||
215 | /** |
||
216 | * Fetch all resultset. |
||
217 | * |
||
218 | * @return array with resultset. |
||
219 | */ |
||
220 | public function fetchAll() |
||
224 | |||
225 | |||
226 | |||
227 | /** |
||
228 | * Fetch one resultset. |
||
229 | * |
||
230 | * @return array with resultset. |
||
231 | */ |
||
232 | public function fetch() |
||
236 | |||
237 | |||
238 | |||
239 | /** |
||
240 | * Fetch one resultset as a new object from this class. |
||
241 | * |
||
242 | * @param object $class which type of object to instantiate. |
||
243 | * |
||
244 | * @return array with resultset. |
||
245 | */ |
||
246 | public function fetchClass($class) |
||
251 | |||
252 | |||
253 | |||
254 | /** |
||
255 | * Fetch full resultset as new objects from this class. |
||
256 | * |
||
257 | * @param object $class which type of object to instantiate. |
||
258 | * |
||
259 | * @return array with resultset. |
||
260 | */ |
||
261 | public function fetchAllClass($class) |
||
266 | |||
267 | |||
268 | |||
269 | /** |
||
270 | * Fetch one resultset into an object. |
||
271 | * |
||
272 | * @param object $object to insert values into. |
||
273 | * |
||
274 | * @return array with resultset. |
||
275 | */ |
||
276 | public function fetchInto($object) |
||
281 | |||
282 | |||
283 | |||
284 | /** |
||
285 | * Execute a SQL-query and ignore the resultset. |
||
286 | * |
||
287 | * @param string $query the SQL statement |
||
288 | * @param array $params the params array |
||
289 | * |
||
290 | * @return self |
||
291 | * |
||
292 | * @throws Exception when failing to prepare question. |
||
293 | */ |
||
294 | 6 | public function execute($query, $params = []) |
|
310 | |||
311 | |||
312 | |||
313 | /** |
||
314 | * Throw exception using detailed message. |
||
315 | * |
||
316 | * @param string $msg detailed error message from PDO |
||
317 | * @param string $query query to execute |
||
318 | * @param array $param to match ? in statement |
||
319 | * |
||
320 | * @return void |
||
321 | * |
||
322 | * @throws \Anax\Database\Exception |
||
323 | */ |
||
324 | protected function createException($msg, $query, $param) |
||
340 | |||
341 | |||
342 | |||
343 | /** |
||
344 | * Throw exception when pdo failed using detailed message. |
||
345 | * |
||
346 | * @param string $query query to execute |
||
347 | * @param array $param to match ? in statement |
||
348 | * |
||
349 | * @return void |
||
350 | * |
||
351 | * @throws \Anax\Database\Exception |
||
352 | */ |
||
353 | protected function pdoException($query, $param) |
||
357 | |||
358 | |||
359 | |||
360 | /** |
||
361 | * Throw exception when statement failed using detailed message. |
||
362 | * |
||
363 | * @param string $query query to execute |
||
364 | * @param array $param to match ? in statement |
||
365 | * |
||
366 | * @return void |
||
367 | * |
||
368 | * @throws \Anax\Database\Exception |
||
369 | */ |
||
370 | protected function statementException($query, $param) |
||
374 | |||
375 | |||
376 | |||
377 | /** |
||
378 | * Return last insert id from autoincremented key on INSERT. |
||
379 | * |
||
380 | * @return integer as last insert id. |
||
381 | */ |
||
382 | 1 | public function lastInsertId() |
|
386 | |||
387 | |||
388 | |||
389 | /** |
||
390 | * Return rows affected of last INSERT, UPDATE, DELETE |
||
391 | * |
||
392 | * @return integer as rows affected on last statement |
||
393 | */ |
||
394 | 1 | public function rowCount() |
|
398 | |||
399 | |||
400 | |||
401 | /** |
||
402 | * Fetch one resultset as an object from this class. |
||
403 | * OBSOLETE replaced by fetchClass |
||
404 | * |
||
405 | * @param object $class which type of object to instantiate. |
||
406 | * |
||
407 | * @return array with resultset. |
||
408 | */ |
||
409 | public function fetchObject($class) |
||
413 | |||
414 | |||
415 | |||
416 | /** |
||
417 | * Fetch one resultset. OBSOLETE replace by fetch() |
||
418 | * |
||
419 | * @return array with resultset. |
||
420 | */ |
||
421 | public function fetchOne() |
||
425 | } |
||
426 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$ireland
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was changed, but the annotation was not.