@@ -93,8 +93,12 @@ public function __construct(
9393 string $ schema = null ,
9494 string $ host = 'localhost ' ,
9595 int $ port = 3306 ,
96- Logger $ logger = null
96+ Logger $ logger = null ,
97+ DatabaseCollector $ collector = null
9798 ) {
99+ if ($ collector ) {
100+ $ this ->setDebugCollector ($ collector );
101+ }
98102 $ this ->logger = $ logger ;
99103 $ this ->connect ($ username , $ password , $ schema , $ host , $ port );
100104 }
@@ -128,6 +132,7 @@ protected function log(string $message, LogLevel $level = LogLevel::ERROR) : voi
128132 'charset ' => 'string ' ,
129133 'collation ' => 'string ' ,
130134 'timezone ' => 'string ' ,
135+ 'init_queries ' => 'bool ' ,
131136 'ssl ' => 'array ' ,
132137 'failover ' => 'array ' ,
133138 'options ' => 'array ' ,
@@ -147,6 +152,7 @@ protected function makeConfig(array $config) : array
147152 'charset ' => 'utf8mb4 ' ,
148153 'collation ' => 'utf8mb4_general_ci ' ,
149154 'timezone ' => '+00:00 ' ,
155+ 'init_queries ' => true ,
150156 'ssl ' => [
151157 'enabled ' => false ,
152158 'verify ' => true ,
@@ -246,8 +252,10 @@ protected function connect(
246252 );
247253 return $ this ->connect ($ config );
248254 }
249- $ this ->setCollations ($ config ['charset ' ], $ config ['collation ' ]);
250- $ this ->setTimezone ($ config ['timezone ' ]);
255+ if ($ config ['init_queries ' ]) {
256+ $ this ->setCollations ($ config ['charset ' ], $ config ['collation ' ]);
257+ $ this ->setTimezone ($ config ['timezone ' ]);
258+ }
251259 return $ this ;
252260 }
253261
@@ -256,13 +264,21 @@ protected function setCollations(string $charset, string $collation) : bool
256264 $ this ->mysqli ->set_charset ($ charset );
257265 $ charset = $ this ->quote ($ charset );
258266 $ collation = $ this ->quote ($ collation );
259- return $ this ->mysqli ->real_query ("SET NAMES {$ charset } COLLATE {$ collation }" );
267+ $ statement = "SET NAMES {$ charset } COLLATE {$ collation }" ;
268+ $ this ->lastQuery = $ statement ;
269+ return isset ($ this ->debugCollector )
270+ ? $ this ->addToDebug (fn () => $ this ->mysqli ->real_query ($ statement ))
271+ : $ this ->mysqli ->real_query ($ statement );
260272 }
261273
262274 protected function setTimezone (string $ timezone ) : bool
263275 {
264276 $ timezone = $ this ->quote ($ timezone );
265- return $ this ->mysqli ->real_query ("SET time_zone = {$ timezone }" );
277+ $ statement = "SET time_zone = {$ timezone }" ;
278+ $ this ->lastQuery = $ statement ;
279+ return isset ($ this ->debugCollector )
280+ ? $ this ->addToDebug (fn () => $ this ->mysqli ->real_query ($ statement ))
281+ : $ this ->mysqli ->real_query ($ statement );
266282 }
267283
268284 /**
@@ -338,6 +354,7 @@ public function reconnect() : static
338354 'charset ' => 'string ' ,
339355 'collation ' => 'string ' ,
340356 'timezone ' => 'string ' ,
357+ 'init_queries ' => 'bool ' ,
341358 'ssl ' => 'array ' ,
342359 'failover ' => 'array ' ,
343360 'options ' => 'array ' ,
0 commit comments