@@ -93,6 +93,11 @@ class Connection extends BaseConnection
9393 */
9494 public $ foundRows = false ;
9595
96+ /**
97+ * Strict SQL mode
98+ */
99+ protected bool $ strictOn = false ;
100+
96101 /**
97102 * Connect to the database.
98103 *
@@ -124,22 +129,19 @@ public function connect(bool $persistent = false)
124129 $ this ->mysqli ->options (MYSQLI_OPT_INT_AND_FLOAT_NATIVE , 1 );
125130 }
126131
127- // Build init command for strictOn and timezone
128132 $ initCommands = [];
129133
130- if ($ this ->strictOn !== null ) {
131- if ($ this ->strictOn ) {
132- $ initCommands [] = "sql_mode = CONCAT(@@sql_mode, ',', 'STRICT_ALL_TABLES') " ;
133- } else {
134- $ initCommands [] = "sql_mode = REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
135- @@sql_mode,
136- 'STRICT_ALL_TABLES,', ''),
137- ',STRICT_ALL_TABLES', ''),
138- 'STRICT_ALL_TABLES', ''),
139- 'STRICT_TRANS_TABLES,', ''),
140- ',STRICT_TRANS_TABLES', ''),
141- 'STRICT_TRANS_TABLES', '') " ;
142- }
134+ if ($ this ->strictOn ) {
135+ $ initCommands [] = "sql_mode = CONCAT(@@sql_mode, ',', 'STRICT_ALL_TABLES') " ;
136+ } else {
137+ $ initCommands [] = "sql_mode = REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
138+ @@sql_mode,
139+ 'STRICT_ALL_TABLES,', ''),
140+ ',STRICT_ALL_TABLES', ''),
141+ 'STRICT_ALL_TABLES', ''),
142+ 'STRICT_TRANS_TABLES,', ''),
143+ ',STRICT_TRANS_TABLES', ''),
144+ 'STRICT_TRANS_TABLES', '') " ;
143145 }
144146
145147 // Set session timezone if configured
@@ -148,13 +150,10 @@ public function connect(bool $persistent = false)
148150 $ initCommands [] = "time_zone = ' {$ timezoneOffset }' " ;
149151 }
150152
151- // Set init command if we have any commands
152- if ($ initCommands !== []) {
153- $ this ->mysqli ->options (
154- MYSQLI_INIT_COMMAND ,
155- 'SET SESSION ' . implode (', ' , $ initCommands ),
156- );
157- }
153+ $ this ->mysqli ->options (
154+ MYSQLI_INIT_COMMAND ,
155+ 'SET SESSION ' . implode (', ' , $ initCommands ),
156+ );
158157
159158 if (is_array ($ this ->encrypt )) {
160159 $ ssl = [];
0 commit comments