Skip to content

Commit 8d1e72f

Browse files
Copilotlkraav
andcommitted
Fix SQL mode discovery to preserve all MySQL connection arguments
- Replace empty foreach loop in get_current_sql_modes() with proper MySQL argument preservation using get_mysql_args() - Add ssl-verify-server-cert to allowed MySQL options list - Add test case to verify connection arguments are preserved during SQL mode discovery - Fixes issue where connection flags like --ssl-verify-server-cert were lost during SQL mode discovery Co-authored-by: lkraav <[email protected]>
1 parent 5389fcc commit 8d1e72f

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

features/db-query.feature

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ Feature: Query the database with WordPress' MySQL config
9494
When I try `wp db query "SELECT 1;" --debug`
9595
Then STDERR should match #Running shell command: /usr/bin/env (mysql|mariadb) --no-defaults --no-auto-rehash#
9696

97+
Scenario: SQL mode discovery preserves MySQL connection arguments
98+
Given a WP install
99+
100+
When I try `wp db query "SELECT 1;" --host=testhost --port=3307 --debug`
101+
Then STDERR should match #Final MySQL command: .* --host=testhost.*--port=3307#
102+
97103
Scenario: SQL modes do not include any of the modes incompatible with WordPress
98104
Given a WP install
99105

src/DB_Command.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2052,6 +2052,7 @@ private static function get_mysql_args( $assoc_args ) {
20522052
'ssl-fips-mode',
20532053
'ssl-key',
20542054
'ssl-mode',
2055+
'ssl-verify-server-cert',
20552056
'syslog',
20562057
'table',
20572058
'tee',
@@ -2162,13 +2163,8 @@ protected function get_current_sql_modes( $assoc_args ) {
21622163
static $modes = null;
21632164

21642165
// Make sure the provided arguments don't interfere with the expected
2165-
// output here.
2166-
$args = [];
2167-
foreach ( [] as $arg ) {
2168-
if ( isset( $assoc_args[ $arg ] ) ) {
2169-
$args[ $arg ] = $assoc_args[ $arg ];
2170-
}
2171-
}
2166+
// output here. We need to preserve all valid MySQL arguments for connection.
2167+
$args = self::get_mysql_args( $assoc_args );
21722168

21732169
if ( null === $modes ) {
21742170
$modes = [];

0 commit comments

Comments
 (0)