Skip to content

Commit ad062d4

Browse files
Copilotswissspidy
andcommitted
Fix SQL mode check to respect custom connection parameters
The get_current_sql_modes() method was ignoring custom connection parameters like --host, --dbuser, and --defaults, causing authentication failures. Now it properly passes these parameters through when checking SQL modes. This fixes the reported issue while maintaining WordPress SQL mode compatibility for queries that need it. Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> Agent-Logs-Url: https://github.com/wp-cli/db-command/sessions/f848d9cd-25e0-4d45-863e-8037bec7af83
1 parent 7923265 commit ad062d4

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

src/DB_Command.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,11 @@ public function query( $args, $assoc_args ) {
605605
$assoc_args['execute'] = $args[0];
606606
}
607607

608+
if ( isset( $assoc_args['execute'] ) ) {
609+
// Ensure that the SQL mode is compatible with WPDB.
610+
$assoc_args['execute'] = $this->get_sql_mode_query( $assoc_args ) . $assoc_args['execute'];
611+
}
612+
608613
$is_row_modifying_query = isset( $assoc_args['execute'] ) && preg_match( '/\b(UPDATE|DELETE|INSERT|REPLACE(?!\s*\()|LOAD DATA)\b/i', $assoc_args['execute'] );
609614

610615
if ( $is_row_modifying_query ) {
@@ -2296,9 +2301,12 @@ protected function get_sql_mode_query( $assoc_args, $modes = [] ) {
22962301
protected function get_current_sql_modes( $assoc_args ) {
22972302
static $modes = null;
22982303

2299-
// Make sure the provided arguments don't interfere with the expected
2300-
// output here.
2301-
$args = [];
2304+
// Pass through connection parameters like host, dbuser, dbpass
2305+
// but filter out other parameters that might interfere with the query output.
2306+
$args = array_merge(
2307+
self::get_dbuser_dbpass_args( $assoc_args ),
2308+
self::get_mysql_args( $assoc_args )
2309+
);
23022310

23032311
if ( null === $modes ) {
23042312
$modes = [];

0 commit comments

Comments
 (0)