1 | <?php |
||
13 | class Database |
||
14 | { |
||
15 | /** |
||
16 | * @var array $options used when creating the PDO object |
||
17 | * @var PDO $pdo the PDO object |
||
18 | * @var PDOStatement $stmt the latest PDOStatement used |
||
19 | */ |
||
20 | protected $options; |
||
21 | private $pdo = null; |
||
22 | private $stmt = null; |
||
23 | |||
24 | |||
25 | |||
26 | /** |
||
27 | * Constructor creating a PDO object connecting to a choosen database. |
||
28 | * |
||
29 | * @param array $options containing details for connecting to the database. |
||
30 | */ |
||
31 | public function __construct($options = []) |
||
35 | |||
36 | |||
37 | |||
38 | /** |
||
39 | * Set options and connection details. |
||
40 | * |
||
41 | * @param array $options containing details for connecting to the database. |
||
42 | * |
||
43 | * @return void |
||
44 | */ |
||
45 | public function setOptions($options = []) |
||
60 | |||
61 | |||
62 | |||
63 | /** |
||
64 | * Set a single option. |
||
65 | * |
||
66 | * @param string $option which to set. |
||
67 | * @param mixed $value to set. |
||
68 | * |
||
69 | * @return self |
||
70 | */ |
||
71 | public function setOption($option, $value) |
||
76 | |||
77 | |||
78 | |||
79 | /** |
||
80 | * Connect to the database, allow being called multiple times |
||
81 | * but ignore when connection is already made. |
||
82 | * |
||
83 | * @return self |
||
84 | * |
||
85 | * @throws \Anax\Database\Exception |
||
86 | */ |
||
87 | public function connect() |
||
116 | |||
117 | |||
118 | |||
119 | public function next() |
||
123 | |||
124 | |||
125 | |||
126 | /** |
||
127 | * Support arrays in params, extract array items and add to $params |
||
128 | * and insert ? for each entry in the array. |
||
129 | * |
||
130 | * @param string $query as the query to prepare. |
||
131 | * @param array $params the parameters that may contain arrays. |
||
132 | * |
||
133 | * @return array with query and params. |
||
134 | */ |
||
135 | private function expandParamArray($query, $params) |
||
162 | |||
163 | |||
164 | |||
165 | /** |
||
166 | * Execute a select-query with arguments and return the resultset. |
||
167 | * |
||
168 | * @param string $query the SQL statement |
||
169 | * @param array $params the params array |
||
170 | * |
||
171 | * @return array with resultset |
||
172 | */ |
||
173 | public function executeFetchAll($query, $params = []) |
||
178 | |||
179 | |||
180 | |||
181 | /** |
||
182 | * Execute a select-query with arguments and return the first row |
||
183 | * in the resultset. |
||
184 | * |
||
185 | * @param string $query the SQL statement |
||
186 | * @param array $params the params array |
||
187 | * |
||
188 | * @return array with resultset |
||
189 | */ |
||
190 | public function executeFetch($query, $params = []) |
||
195 | |||
196 | |||
197 | |||
198 | /** |
||
199 | * Execute a select-query with arguments and insert the results into |
||
200 | * a new object of the class. |
||
201 | * |
||
202 | * @param string $query the SQL statement |
||
203 | * @param array $params the params array |
||
204 | * @param string $class the class to create an object of and insert into |
||
205 | * |
||
206 | * @return array with resultset |
||
207 | */ |
||
208 | public function executeFetchClass($query, $params, $class) |
||
214 | |||
215 | |||
216 | |||
217 | /** |
||
218 | * Execute a select-query with arguments and insert the results into |
||
219 | * an existing object. |
||
220 | * |
||
221 | * @param string $query the SQL statement |
||
222 | * @param array $params the params array |
||
|
|||
223 | * @param string $object the existing object to insert into |
||
224 | * |
||
225 | * @return array with resultset |
||
226 | */ |
||
227 | public function executeFetchInto($query, $param, $object = null) |
||
237 | |||
238 | |||
239 | |||
240 | /** |
||
241 | * Fetch all resultset. |
||
242 | * |
||
243 | * @return array with resultset. |
||
244 | */ |
||
245 | public function fetchAll() |
||
249 | |||
250 | |||
251 | |||
252 | /** |
||
253 | * Fetch one resultset. |
||
254 | * |
||
255 | * @return array with resultset. |
||
256 | */ |
||
257 | public function fetch() |
||
261 | |||
262 | |||
263 | |||
264 | /** |
||
265 | * Fetch one resultset as a new object from this class. |
||
266 | * |
||
267 | * @param object $class which type of object to instantiate. |
||
268 | * |
||
269 | * @return array with resultset. |
||
270 | */ |
||
271 | public function fetchClass($class) |
||
276 | |||
277 | |||
278 | |||
279 | /** |
||
280 | * Fetch full resultset as new objects from this class. |
||
281 | * |
||
282 | * @param object $class which type of object to instantiate. |
||
283 | * |
||
284 | * @return array with resultset. |
||
285 | */ |
||
286 | public function fetchAllClass($class) |
||
291 | |||
292 | |||
293 | |||
294 | /** |
||
295 | * Fetch one resultset into an object. |
||
296 | * |
||
297 | * @param object $object to insert values into. |
||
298 | * |
||
299 | * @return array with resultset. |
||
300 | */ |
||
301 | public function fetchInto($object) |
||
306 | |||
307 | |||
308 | |||
309 | /** |
||
310 | * Execute a SQL-query and ignore the resultset. |
||
311 | * |
||
312 | * @param string $query the SQL statement |
||
313 | * @param array $params the params array |
||
314 | * |
||
315 | * @return self |
||
316 | * |
||
317 | * @throws Exception when failing to prepare question. |
||
318 | */ |
||
319 | public function execute($query, $params = []) |
||
340 | |||
341 | |||
342 | |||
343 | /** |
||
344 | * Throw exception using detailed message. |
||
345 | * |
||
346 | * @param string $msg detailed error message from PDO |
||
347 | * @param string $query query to execute |
||
348 | * @param array $param to match ? in statement |
||
349 | * |
||
350 | * @return void |
||
351 | * |
||
352 | * @throws \Anax\Database\Exception |
||
353 | */ |
||
354 | protected function createException($msg, $query, $param) |
||
370 | |||
371 | |||
372 | |||
373 | /** |
||
374 | * Throw exception when pdo failed using detailed message. |
||
375 | * |
||
376 | * @param string $query query to execute |
||
377 | * @param array $param to match ? in statement |
||
378 | * |
||
379 | * @return void |
||
380 | * |
||
381 | * @throws \Anax\Database\Exception |
||
382 | */ |
||
383 | protected function pdoException($query, $param) |
||
387 | |||
388 | |||
389 | |||
390 | /** |
||
391 | * Throw exception when statement failed using detailed message. |
||
392 | * |
||
393 | * @param string $query query to execute |
||
394 | * @param array $param to match ? in statement |
||
395 | * |
||
396 | * @return void |
||
397 | * |
||
398 | * @throws \Anax\Database\Exception |
||
399 | */ |
||
400 | protected function statementException($query, $param) |
||
404 | |||
405 | |||
406 | |||
407 | /** |
||
408 | * Return last insert id from autoincremented key on INSERT. |
||
409 | * |
||
410 | * @return integer as last insert id. |
||
411 | */ |
||
412 | public function lastInsertId() |
||
416 | |||
417 | |||
418 | |||
419 | /** |
||
420 | * Return rows affected of last INSERT, UPDATE, DELETE |
||
421 | * |
||
422 | * @return integer as rows affected on last statement |
||
423 | */ |
||
424 | public function rowCount() |
||
428 | |||
429 | |||
430 | |||
431 | /** |
||
432 | * Fetch one resultset as an object from this class. |
||
433 | * OBSOLETE replaced by fetchClass |
||
434 | * |
||
435 | * @param object $class which type of object to instantiate. |
||
436 | * |
||
437 | * @return array with resultset. |
||
438 | */ |
||
439 | public function fetchObject($class) |
||
443 | |||
444 | |||
445 | |||
446 | /** |
||
447 | * Fetch one resultset. OBSOLETE replace by fetch() |
||
448 | * |
||
449 | * @return array with resultset. |
||
450 | */ |
||
451 | public function fetchOne() |
||
455 | } |
||
456 |
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.