1 | <?php |
||
14 | class Database |
||
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 | /** |
||
29 | * Connect to a database using driver with parameters |
||
30 | * @param string $database Database name |
||
31 | * @param string $username Database username |
||
32 | * @param string $password Database password |
||
33 | * @param string $host Database host(localhost by default) |
||
34 | * @param int $port Database port(3306 by default) |
||
35 | * @param string $driver Database driver for interaction(MySQL by default) |
||
36 | * @param string $charset Database character set |
||
37 | * @return bool True if connection to database was successful |
||
38 | */ |
||
39 | public function connect( |
||
63 | |||
64 | /** |
||
65 | * Get database name |
||
66 | * @return string |
||
67 | */ |
||
68 | public function database() |
||
72 | |||
73 | /** |
||
74 | * High-level database query executor |
||
75 | * @param string $sql SQL statement |
||
76 | * @return mixed Database query result |
||
77 | * @deprecated Use execute() |
||
78 | */ |
||
79 | public function query($sql) |
||
83 | |||
84 | |||
85 | |||
86 | /** |
||
87 | * Intreal error beautifier |
||
88 | * @param \Exception $exception |
||
89 | * @param $sql |
||
90 | */ |
||
91 | private function outputError(\Exception $exception, $sql, $text = 'Error executing database query:') |
||
98 | |||
99 | /** |
||
100 | * Proxy function for executing database fetching logic with exception, |
||
101 | * error, profile handling |
||
102 | * @param callback $fetcher Callback for fetching |
||
103 | * @return mixed Fetching function result |
||
104 | */ |
||
105 | private function executeFetcher($fetcher, $sql) |
||
133 | |||
134 | /** |
||
135 | * High-level database query executor |
||
136 | * @param string $sql SQL statement |
||
137 | * @return mixed Database query result |
||
138 | */ |
||
139 | private function innerQuery($sql) |
||
150 | |||
151 | /** |
||
152 | * Retrieve array of records from a database, if $className is passed method |
||
153 | * will try to create an object of that type. If request has failed than |
||
154 | * method will return empty array of stdClass all arrays regarding to $className is |
||
155 | * passed or not. |
||
156 | * |
||
157 | * @param string $sql SQL statement |
||
158 | * @return array Collection of arrays or objects |
||
159 | */ |
||
160 | private function innerFetch($sql, $className = null) |
||
175 | |||
176 | /** |
||
177 | * Special accelerated function to retrieve db record fields instead of objects |
||
178 | * |
||
179 | * @param string $sql SQL statement |
||
180 | * @param int $columnIndex Needed column index |
||
181 | * |
||
182 | * @return array Database records column value collection |
||
183 | */ |
||
184 | private function innerFetchColumn($sql, $columnIndex) |
||
195 | |||
196 | /** |
||
197 | * High-level database query executor |
||
198 | * @param string $sql SQL statement |
||
199 | * @return mixed Database query result |
||
200 | */ |
||
201 | public function execute($sql) |
||
205 | |||
206 | /** |
||
207 | * Retrieve array of records from a database, if $className is passed method |
||
208 | * will try to create an object of that type. If request has failed than |
||
209 | * method will return empty array of stdClass all arrays regarding to $className is |
||
210 | * passed or not. |
||
211 | * |
||
212 | * @param string $sql SQL statement |
||
213 | * @return array Collection of arrays or objects |
||
214 | */ |
||
215 | public function fetch($sql) |
||
219 | |||
220 | /** |
||
221 | * Special accelerated function to retrieve db record fields instead of objects |
||
222 | * TODO: Change to be independent of query and class name, just SQL, this SQL |
||
223 | * should only have one column in SELECT part and then we do not need parameter |
||
224 | * for this as we can always take 0. |
||
225 | * |
||
226 | * @param string $className |
||
227 | * @param mixed $query |
||
228 | * @param string $field |
||
229 | * |
||
230 | * @return array |
||
231 | */ |
||
232 | public function fetchColumn($className, $query, $field) |
||
243 | |||
244 | /** |
||
245 | * Quote variable for security reasons. |
||
246 | * |
||
247 | * @param string $value |
||
248 | * @return string Quoted value |
||
249 | */ |
||
250 | protected function quote($value) |
||
254 | } |
||
255 |
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..