1 | <?php |
||
14 | class Database implements DatabaseInterface |
||
15 | { |
||
16 | /** @var \PDO Database driver */ |
||
17 | protected $driver; |
||
18 | |||
19 | /** @var string Database name */ |
||
20 | protected $database; |
||
21 | |||
22 | /** @var int Amount of milliseconds spent on queries */ |
||
23 | protected $elapsed; |
||
24 | |||
25 | /** @var int Amount queries executed */ |
||
26 | protected $count; |
||
27 | |||
28 | /** Do not serialize anything */ |
||
29 | public function __sleep() |
||
33 | |||
34 | /** |
||
35 | * Connect to a database using driver with parameters |
||
36 | * @param string $database Database name |
||
37 | * @param string $username Database username |
||
38 | * @param string $password Database password |
||
39 | * @param string $host Database host(localhost by default) |
||
40 | * @param int $port Database port(3306 by default) |
||
41 | * @param string $driver Database driver for interaction(MySQL by default) |
||
42 | * @param string $charset Database character set |
||
43 | * @return bool True if connection to database was successful |
||
44 | */ |
||
45 | public function connect( |
||
69 | |||
70 | /** |
||
71 | * Get database name |
||
72 | * @return string |
||
73 | */ |
||
74 | public function database() |
||
78 | |||
79 | /** |
||
80 | * High-level database query executor |
||
81 | * @param string $sql SQL statement |
||
82 | * @return mixed Database query result |
||
83 | * @deprecated Use execute() |
||
84 | */ |
||
85 | public function query($sql) |
||
89 | |||
90 | /** |
||
91 | * Intreal error beautifier |
||
92 | * @param \Exception $exception |
||
93 | * @param $sql |
||
94 | */ |
||
95 | private function outputError(\Exception $exception, $sql, $text = 'Error executing database query:') |
||
102 | |||
103 | /** |
||
104 | * Proxy function for executing database fetching logic with exception, |
||
105 | * error, profile handling |
||
106 | * @param callback $fetcher Callback for fetching |
||
107 | * @return mixed Fetching function result |
||
108 | */ |
||
109 | private function executeFetcher($fetcher, $sql) |
||
137 | |||
138 | /** |
||
139 | * High-level database query executor |
||
140 | * @param string $sql SQL statement |
||
141 | * @return mixed Database query result |
||
142 | */ |
||
143 | private function innerQuery($sql) |
||
154 | |||
155 | /** |
||
156 | * Retrieve array of records from a database, if $className is passed method |
||
157 | * will try to create an object of that type. If request has failed than |
||
158 | * method will return empty array of stdClass all arrays regarding to $className is |
||
159 | * passed or not. |
||
160 | * |
||
161 | * @param string $sql SQL statement |
||
162 | * @return array Collection of arrays or objects |
||
163 | */ |
||
164 | private function innerFetch($sql, $className = null) |
||
179 | |||
180 | /** |
||
181 | * Special accelerated function to retrieve db record fields instead of objects |
||
182 | * |
||
183 | * @param string $sql SQL statement |
||
184 | * @param int $columnIndex Needed column index |
||
185 | * |
||
186 | * @return array Database records column value collection |
||
187 | */ |
||
188 | private function innerFetchColumn($sql, $columnIndex) |
||
199 | |||
200 | /** |
||
201 | * High-level database query executor |
||
202 | * @param string $sql SQL statement |
||
203 | * @return mixed Database query result |
||
204 | */ |
||
205 | public function execute($sql) |
||
209 | |||
210 | /** |
||
211 | * Retrieve array of records from a database, if $className is passed method |
||
212 | * will try to create an object of that type. If request has failed than |
||
213 | * method will return empty array of stdClass all arrays regarding to $className is |
||
214 | * passed or not. |
||
215 | * |
||
216 | * @param string $sql SQL statement |
||
217 | * @return array Collection of arrays or objects |
||
218 | */ |
||
219 | public function fetch($sql) |
||
223 | |||
224 | /** |
||
225 | * Special accelerated function to retrieve db record fields instead of objects |
||
226 | * TODO: Change to be independent of query and class name, just SQL, this SQL |
||
227 | * should only have one column in SELECT part and then we do not need parameter |
||
228 | * for this as we can always take 0. |
||
229 | * |
||
230 | * @param string $entity Entity identifier |
||
231 | * @param QueryInterface Query object |
||
232 | * @param string $field Entity field identifier |
||
233 | * |
||
234 | * @return array Collection of rows with field value |
||
235 | */ |
||
236 | public function fetchColumn($entity, QueryInterface $query, $field) |
||
246 | |||
247 | /** |
||
248 | * Count resulting rows. |
||
249 | * |
||
250 | * @param string Entity identifier |
||
251 | * @param QueryInterface Query object |
||
252 | * |
||
253 | * @return int Amount of rows |
||
254 | */ |
||
255 | public function count($entity, QueryInterface $query) |
||
262 | |||
263 | /** |
||
264 | * Quote variable for security reasons. |
||
265 | * |
||
266 | * @param string $value |
||
267 | * @return string Quoted value |
||
268 | */ |
||
269 | protected function quote($value) |
||
273 | |||
274 | /** |
||
275 | * Convert QueryInterface into SQL statement. |
||
276 | * |
||
277 | * @param string Entity identifier |
||
278 | * @param QueryInterface Query object |
||
279 | * |
||
280 | * @return string SQL statement |
||
281 | */ |
||
282 | protected function prepareSQL($entity, QueryInterface $query) |
||
286 | } |
||
287 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..