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 | 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 | public function setOptions($options = []) |
||
58 | |||
59 | |||
60 | |||
61 | /** |
||
62 | * Set a single option. |
||
63 | * |
||
64 | * @param string $option which to set. |
||
65 | * @param mixed $value to set. |
||
66 | * |
||
67 | * @return self |
||
68 | */ |
||
69 | public function setOption($option, $value) |
||
74 | |||
75 | |||
76 | |||
77 | /** |
||
78 | * Connect to the database, allow being called multiple times |
||
79 | * but ignore when connection is already made. |
||
80 | * |
||
81 | * @return self |
||
82 | * |
||
83 | * @throws \Anax\Database\Exception |
||
84 | */ |
||
85 | public function connect() |
||
114 | |||
115 | |||
116 | |||
117 | public function next() |
||
121 | |||
122 | |||
123 | |||
124 | /** |
||
125 | * Support arrays in params, extract array items and add to $params |
||
126 | * and insert ? for each entry in the array. |
||
127 | * |
||
128 | * @param string $query as the query to prepare. |
||
129 | * @param array $params the parameters that may contain arrays. |
||
130 | * |
||
131 | * @return array with query and params. |
||
132 | */ |
||
133 | private function expandParamArray($query, $params) |
||
160 | |||
161 | |||
162 | |||
163 | /** |
||
164 | * Execute a select-query with arguments and return the resultset. |
||
165 | * |
||
166 | * @param string $query the SQL statement |
||
167 | * @param array $params the params array |
||
168 | * |
||
169 | * @return array with resultset |
||
170 | */ |
||
171 | public function executeFetchAll($query, $params = []) |
||
176 | |||
177 | |||
178 | |||
179 | /** |
||
180 | * Execute a select-query with arguments and return the first row |
||
181 | * in the resultset. |
||
182 | * |
||
183 | * @param string $query the SQL statement |
||
184 | * @param array $params the params array |
||
185 | * |
||
186 | * @return array with resultset |
||
187 | */ |
||
188 | public function executeFetch($query, $params = []) |
||
193 | |||
194 | |||
195 | |||
196 | /** |
||
197 | * Execute a select-query with arguments and insert the results into |
||
198 | * a new object of the class. |
||
199 | * |
||
200 | * @param string $query the SQL statement |
||
201 | * @param array $params the params array |
||
202 | * @param string $class the class to create an object of and insert into |
||
203 | * |
||
204 | * @return array with resultset |
||
205 | */ |
||
206 | public function executeFetchClass($query, $params, $class) |
||
212 | |||
213 | |||
214 | |||
215 | /** |
||
216 | * Execute a select-query with arguments and insert the results into |
||
217 | * an existing object. |
||
218 | * |
||
219 | * @param string $query the SQL statement |
||
220 | * @param array $params the params array |
||
|
|||
221 | * @param string $object the existing object to insert into |
||
222 | * |
||
223 | * @return array with resultset |
||
224 | */ |
||
225 | public function executeFetchInto($query, $param, $object = null) |
||
235 | |||
236 | |||
237 | |||
238 | /** |
||
239 | * Fetch all resultset. |
||
240 | * |
||
241 | * @return array with resultset. |
||
242 | */ |
||
243 | public function fetchAll() |
||
247 | |||
248 | |||
249 | |||
250 | /** |
||
251 | * Fetch one resultset. |
||
252 | * |
||
253 | * @return array with resultset. |
||
254 | */ |
||
255 | public function fetch() |
||
259 | |||
260 | |||
261 | |||
262 | /** |
||
263 | * Fetch one resultset as a new object from this class. |
||
264 | * |
||
265 | * @param object $class which type of object to instantiate. |
||
266 | * |
||
267 | * @return array with resultset. |
||
268 | */ |
||
269 | public function fetchClass($class) |
||
274 | |||
275 | |||
276 | |||
277 | /** |
||
278 | * Fetch full resultset as new objects from this class. |
||
279 | * |
||
280 | * @param object $class which type of object to instantiate. |
||
281 | * |
||
282 | * @return array with resultset. |
||
283 | */ |
||
284 | public function fetchAllClass($class) |
||
289 | |||
290 | |||
291 | |||
292 | /** |
||
293 | * Fetch one resultset into an object. |
||
294 | * |
||
295 | * @param object $object to insert values into. |
||
296 | * |
||
297 | * @return array with resultset. |
||
298 | */ |
||
299 | public function fetchInto($object) |
||
304 | |||
305 | |||
306 | |||
307 | /** |
||
308 | * Execute a SQL-query and ignore the resultset. |
||
309 | * |
||
310 | * @param string $query the SQL statement |
||
311 | * @param array $params the params array |
||
312 | * |
||
313 | * @return self |
||
314 | * |
||
315 | * @throws Exception when failing to prepare question. |
||
316 | */ |
||
317 | public function execute($query, $params = []) |
||
338 | |||
339 | |||
340 | |||
341 | /** |
||
342 | * Throw exception using detailed message. |
||
343 | * |
||
344 | * @param string $msg detailed error message from PDO |
||
345 | * @param string $query query to execute |
||
346 | * @param array $param to match ? in statement |
||
347 | * |
||
348 | * @return void |
||
349 | * |
||
350 | * @throws \Anax\Database\Exception |
||
351 | */ |
||
352 | protected function createException($msg, $query, $param) |
||
368 | |||
369 | |||
370 | |||
371 | /** |
||
372 | * Throw exception when pdo failed using detailed message. |
||
373 | * |
||
374 | * @param string $query query to execute |
||
375 | * @param array $param to match ? in statement |
||
376 | * |
||
377 | * @return void |
||
378 | * |
||
379 | * @throws \Anax\Database\Exception |
||
380 | */ |
||
381 | protected function pdoException($query, $param) |
||
385 | |||
386 | |||
387 | |||
388 | /** |
||
389 | * Throw exception when statement failed using detailed message. |
||
390 | * |
||
391 | * @param string $query query to execute |
||
392 | * @param array $param to match ? in statement |
||
393 | * |
||
394 | * @return void |
||
395 | * |
||
396 | * @throws \Anax\Database\Exception |
||
397 | */ |
||
398 | protected function statementException($query, $param) |
||
402 | |||
403 | |||
404 | |||
405 | /** |
||
406 | * Return last insert id from autoincremented key on INSERT. |
||
407 | * |
||
408 | * @return integer as last insert id. |
||
409 | */ |
||
410 | public function lastInsertId() |
||
414 | |||
415 | |||
416 | |||
417 | /** |
||
418 | * Return rows affected of last INSERT, UPDATE, DELETE |
||
419 | * |
||
420 | * @return integer as rows affected on last statement |
||
421 | */ |
||
422 | public function rowCount() |
||
426 | |||
427 | |||
428 | |||
429 | /** |
||
430 | * Fetch one resultset as an object from this class. |
||
431 | * OBSOLETE replaced by fetchClass |
||
432 | * |
||
433 | * @param object $class which type of object to instantiate. |
||
434 | * |
||
435 | * @return array with resultset. |
||
436 | */ |
||
437 | public function fetchObject($class) |
||
441 | |||
442 | |||
443 | |||
444 | /** |
||
445 | * Fetch one resultset. OBSOLETE replace by fetch() |
||
446 | * |
||
447 | * @return array with resultset. |
||
448 | */ |
||
449 | public function fetchOne() |
||
453 | } |
||
454 |
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.