Skip to content

Commit e4b351b

Browse files
swissspidyCopilot
andauthored
Update src/DB_Command.php
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 1693bf9 commit e4b351b

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/DB_Command.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,12 +1854,26 @@ private static function run( $cmd, $assoc_args = [], $send_to_shell = true, $int
18541854
$final_args = array_merge( $required, $assoc_args );
18551855

18561856
// Filter out empty string values to avoid passing empty parameters to MySQL commands
1857-
// which can cause errors like "Character set '' is not a compiled character set"
1857+
// which can cause errors like "Character set '' is not a compiled character set".
1858+
// However, keep empty strings for credential options like 'user' and 'pass' so that
1859+
// an explicitly empty value is not silently converted into an omitted parameter.
18581860
$final_args = array_filter(
18591861
$final_args,
1860-
static function ( $value ) {
1861-
return null !== $value && '' !== $value;
1862-
}
1862+
static function ( $value, $key ) {
1863+
// Always drop null values.
1864+
if ( null === $value ) {
1865+
return false;
1866+
}
1867+
1868+
// Preserve explicitly empty credential arguments.
1869+
if ( '' === $value && in_array( $key, [ 'user', 'pass' ], true ) ) {
1870+
return true;
1871+
}
1872+
1873+
// For all other options, filter out empty strings.
1874+
return '' !== $value;
1875+
},
1876+
ARRAY_FILTER_USE_BOTH
18631877
);
18641878

18651879
// Adapt ordering of arguments.

0 commit comments

Comments
 (0)