1 | <?php |
||
9 | class Database |
||
10 | { |
||
11 | /** |
||
12 | * @var array $options used when creating the PDO object |
||
13 | * @var PDO $pdo the PDO object |
||
14 | * @var PDOStatement $stmt the latest PDOStatement used |
||
15 | */ |
||
16 | private $options; |
||
17 | private $pdo = null; |
||
18 | private $stmt = null; |
||
19 | |||
20 | |||
21 | |||
22 | /** |
||
23 | * Constructor creating a PDO object connecting to a choosen database. |
||
24 | * |
||
25 | * @param array $options containing details for connecting to the database. |
||
26 | */ |
||
27 | 7 | public function __construct($options = []) |
|
31 | |||
32 | |||
33 | |||
34 | /** |
||
35 | * Set options and connection details. |
||
36 | * |
||
37 | * @param array $options containing details for connecting to the database. |
||
38 | * |
||
39 | * @return void |
||
40 | */ |
||
41 | 7 | public function setOptions($options = []) |
|
56 | |||
57 | |||
58 | |||
59 | /** |
||
60 | * Connect to the database. |
||
61 | * |
||
62 | * @return self |
||
63 | * |
||
64 | * @throws \Anax\Database\Exception |
||
65 | */ |
||
66 | 7 | public function connect() |
|
91 | |||
92 | |||
93 | |||
94 | /** |
||
95 | * Support arrays in params, extract array items and add to $params |
||
96 | * and insert ? for each entry in the array. |
||
97 | * |
||
98 | * @param string $query as the query to prepare. |
||
99 | * @param array $params the parameters that may contain arrays. |
||
100 | * |
||
101 | * @return array with query and params. |
||
102 | */ |
||
103 | 3 | private function expandParamArray($query, $params) |
|
130 | |||
131 | |||
132 | |||
133 | /** |
||
134 | * Execute a select-query with arguments and return the resultset. |
||
135 | * |
||
136 | * @param string $query the SQL statement |
||
137 | * @param array $params the params array |
||
138 | * |
||
139 | * @return array with resultset |
||
140 | */ |
||
141 | public function executeFetchAll($query, $params = []) |
||
146 | |||
147 | |||
148 | |||
149 | /** |
||
150 | * Execute a select-query with arguments and return the first row |
||
151 | * in the resultset. |
||
152 | * |
||
153 | * @param string $query the SQL statement |
||
154 | * @param array $params the params array |
||
155 | * |
||
156 | * @return array with resultset |
||
157 | */ |
||
158 | public function executeFetch($query, $params = []) |
||
163 | |||
164 | |||
165 | |||
166 | /** |
||
167 | * Execute a select-query with arguments and insert the results into |
||
168 | * a new object of the class. |
||
169 | * |
||
170 | * @param string $query the SQL statement |
||
171 | * @param array $params the params array |
||
172 | * @param string $class the class to create an object of and insert into |
||
173 | * |
||
174 | * @return array with resultset |
||
175 | */ |
||
176 | public function executeFetchClass($query, $params, $class) |
||
182 | |||
183 | |||
184 | |||
185 | /** |
||
186 | * Execute a select-query with arguments and insert the results into |
||
187 | * an existing object. |
||
188 | * |
||
189 | * @param string $query the SQL statement |
||
|
|||
190 | * @param array $params the params array |
||
191 | * @param string $object the existing object to insert into |
||
192 | * |
||
193 | * @return array with resultset |
||
194 | */ |
||
195 | public function executeFetchInto($sql, $param, $object = null) |
||
205 | |||
206 | |||
207 | |||
208 | /** |
||
209 | * Fetch all resultset. |
||
210 | * |
||
211 | * @return array with resultset. |
||
212 | */ |
||
213 | public function fetchAll() |
||
217 | |||
218 | |||
219 | |||
220 | /** |
||
221 | * Fetch one resultset. |
||
222 | * |
||
223 | * @return array with resultset. |
||
224 | */ |
||
225 | public function fetch() |
||
229 | |||
230 | |||
231 | |||
232 | /** |
||
233 | * Fetch one resultset as a new object from this class. |
||
234 | * |
||
235 | * @param object $class which type of object to instantiate. |
||
236 | * |
||
237 | * @return array with resultset. |
||
238 | */ |
||
239 | public function fetchClass($class) |
||
244 | |||
245 | |||
246 | |||
247 | /** |
||
248 | * Fetch one resultset into an object. |
||
249 | * |
||
250 | * @param object $object to insert values into. |
||
251 | * |
||
252 | * @return array with resultset. |
||
253 | */ |
||
254 | public function fetchInto($object) |
||
259 | |||
260 | |||
261 | |||
262 | /** |
||
263 | * Execute a SQL-query and ignore the resultset. |
||
264 | * |
||
265 | * @param string $query the SQL statement |
||
266 | * @param array $params the params array |
||
267 | * |
||
268 | * @return boolean returns TRUE on success or FALSE on failure. |
||
269 | * |
||
270 | * @throws Exception when failing to prepare question. |
||
271 | */ |
||
272 | 3 | public function execute($query, $params = []) |
|
288 | |||
289 | |||
290 | |||
291 | /** |
||
292 | * Through exception with detailed message. |
||
293 | * |
||
294 | * @param string $sql statement to execute |
||
295 | * @param array $param to match ? in statement |
||
296 | * |
||
297 | * @return void |
||
298 | * |
||
299 | * @throws \Anax\Database\Exception |
||
300 | */ |
||
301 | private function statementException($sql, $param) |
||
317 | |||
318 | |||
319 | |||
320 | /** |
||
321 | * Return last insert id from autoincremented key on INSERT. |
||
322 | * |
||
323 | * @return integer as last insert id. |
||
324 | */ |
||
325 | public function lastInsertId() |
||
329 | |||
330 | |||
331 | |||
332 | /** |
||
333 | * Return rows affected of last INSERT, UPDATE, DELETE |
||
334 | * |
||
335 | * @return integer as rows affected on last statement |
||
336 | */ |
||
337 | public function rowCount() |
||
341 | |||
342 | |||
343 | |||
344 | /** |
||
345 | * Fetch one resultset as an object from this class. |
||
346 | * OBSOLETE replaced by fetchClass |
||
347 | * |
||
348 | * @param object $class which type of object to instantiate. |
||
349 | * |
||
350 | * @return array with resultset. |
||
351 | */ |
||
352 | public function fetchObject($class) |
||
356 | |||
357 | |||
358 | |||
359 | /** |
||
360 | * Fetch one resultset. OBSOLETE replace by fetch() |
||
361 | * |
||
362 | * @return array with resultset. |
||
363 | */ |
||
364 | public function fetchOne() |
||
368 | } |
||
369 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.