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( |
||
61 | |||
62 | /** |
||
63 | * Get database name |
||
64 | * @return string |
||
65 | */ |
||
66 | public function database() |
||
70 | |||
71 | /** |
||
72 | * High-level database query executor |
||
73 | * @param string $sql SQL statement |
||
74 | * @return mixed Database query result |
||
75 | * @deprecated Use execute() |
||
76 | */ |
||
77 | public function query($sql) |
||
81 | |||
82 | |||
83 | |||
84 | /** |
||
85 | * Intreal error beautifier |
||
86 | * @param \Exception $exception |
||
87 | * @param $sql |
||
88 | */ |
||
89 | private function outputError(\Exception $exception, $sql, $text = 'Error executing database query:') |
||
96 | |||
97 | /** |
||
98 | * Proxy function for executing database fetching logic with exception, |
||
99 | * error, profile handling |
||
100 | * @param callback $fetcher Callback for fetching |
||
101 | * @return mixed Fetching function result |
||
102 | */ |
||
103 | private function executeFetcher($fetcher, $sql) |
||
131 | |||
132 | /** |
||
133 | * High-level database query executor |
||
134 | * @param string $sql SQL statement |
||
135 | * @return mixed Database query result |
||
136 | */ |
||
137 | private function innerQuery($sql) |
||
148 | |||
149 | /** |
||
150 | * Retrieve array of records from a database, if $className is passed method |
||
151 | * will try to create an object of that type. If request has failed than |
||
152 | * method will return empty array of stdClass all arrays regarding to $className is |
||
153 | * passed or not. |
||
154 | * |
||
155 | * @param string $sql SQL statement |
||
156 | * @return array Collection of arrays or objects |
||
157 | */ |
||
158 | private function innerFetch($sql, $className = null) |
||
173 | |||
174 | /** |
||
175 | * Special accelerated function to retrieve db record fields instead of objects |
||
176 | * |
||
177 | * @param string $sql SQL statement |
||
178 | * @param int $columnIndex Needed column index |
||
179 | * |
||
180 | * @return array Database records column value collection |
||
181 | */ |
||
182 | private function innerFetchColumn($sql, $columnIndex) |
||
193 | |||
194 | /** |
||
195 | * High-level database query executor |
||
196 | * @param string $sql SQL statement |
||
197 | * @return mixed Database query result |
||
198 | */ |
||
199 | public function execute($sql) |
||
203 | |||
204 | /** |
||
205 | * Retrieve array of records from a database, if $className is passed method |
||
206 | * will try to create an object of that type. If request has failed than |
||
207 | * method will return empty array of stdClass all arrays regarding to $className is |
||
208 | * passed or not. |
||
209 | * |
||
210 | * @param string $sql SQL statement |
||
211 | * @return array Collection of arrays or objects |
||
212 | */ |
||
213 | public function fetch($sql) |
||
217 | |||
218 | /** |
||
219 | * Special accelerated function to retrieve db record fields instead of objects |
||
220 | * TODO: Change to be independent of query and class name, just SQL, this SQL |
||
221 | * should only have one column in SELECT part and then we do not need parameter |
||
222 | * for this as we can always take 0. |
||
223 | * |
||
224 | * @param string $className |
||
225 | * @param mixed $query |
||
226 | * @param string $field |
||
227 | * |
||
228 | * @return array |
||
229 | */ |
||
230 | public function fetchColumn($className, $query, $field) |
||
241 | |||
242 | /** |
||
243 | * Quote variable for security reasons. |
||
244 | * |
||
245 | * @param string $value |
||
246 | * @return string Quoted value |
||
247 | */ |
||
248 | protected function quote($value) |
||
252 | } |
||
253 |
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..