1 | <?php |
||
11 | class Db |
||
12 | { |
||
13 | /** |
||
14 | * @var Config |
||
15 | */ |
||
16 | protected $config; |
||
17 | /** |
||
18 | * @var Logger |
||
19 | */ |
||
20 | protected $log; |
||
21 | /** |
||
22 | * @var \PDO |
||
23 | */ |
||
24 | private $pdo; |
||
25 | /** |
||
26 | * @var Container |
||
27 | */ |
||
28 | private $container; |
||
29 | |||
30 | /** |
||
31 | * Db constructor. |
||
32 | * @param Config $config |
||
33 | * @param Logger $log |
||
34 | * @param Container $container |
||
35 | */ |
||
36 | public function __construct(Config $config, Logger $log, Container $container) |
||
43 | |||
44 | /** |
||
45 | * @return array |
||
46 | * Upon sleeping (which is needed for pthreads to work with pdo) we just return an empty array, which is the default for all the query functions anyway |
||
47 | * It doesn't really matter what we return tho, since once the thread wakes up, the __wakeup function is ran |
||
48 | */ |
||
49 | public function __sleep() |
||
53 | |||
54 | /** |
||
55 | * This is for the pthreads compatibility - for some reason the DB just goes tits up when using pthreads |
||
56 | * and PDO.. Hence the __wakeup() call, that restarts the database. |
||
57 | * No numbers on it, but it more than likely adds quite a bit of latency. |
||
58 | */ |
||
59 | public function __wakeup() |
||
66 | |||
67 | /** |
||
68 | * @return \PDO |
||
69 | */ |
||
70 | private function connect() |
||
88 | |||
89 | /** |
||
90 | * @param String $query |
||
91 | * @param array $parameters |
||
92 | * @return array |
||
93 | */ |
||
94 | public function queryRow(String $query, $parameters = array()) |
||
104 | |||
105 | /** |
||
106 | * @param String $query |
||
107 | * @param array $parameters |
||
108 | * @return array |
||
109 | */ |
||
110 | public function query(String $query, $parameters = array()) |
||
136 | |||
137 | /** |
||
138 | * @param String $query |
||
139 | * @param String $field |
||
140 | * @param array $parameters |
||
141 | * @return string |
||
142 | */ |
||
143 | public function queryField(String $query, String $field, $parameters = array()) |
||
154 | |||
155 | /** |
||
156 | * @param String $query |
||
157 | * @param array $parameters |
||
158 | * @return int|null|string |
||
159 | */ |
||
160 | public function execute(String $query, $parameters = array()) |
||
189 | } |
||
190 |
An exit expression should only be used in rare cases. For example, if you write a short command line script.
In most cases however, using an
exit
expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.