Skip to content

Commit 38a7476

Browse files
committed
Support specifying database name in authentication phase
1 parent f77f6ff commit 38a7476

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

packages/wp-mysql-proxy/src/class-mysql-session.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,17 @@ private function process_authentication( string $payload ): string {
251251
// Get the database name.
252252
if ( $client_flags & MySQL_Protocol::CLIENT_CONNECT_WITH_DB ) {
253253
$database = MySQL_Protocol::read_null_terminated_string( $payload, $offset );
254+
if ( '' !== $database ) {
255+
$result = $this->adapter->handle_query( 'USE ' . $database );
256+
if ( $result->error_info ) {
257+
return MySQL_Protocol::build_err_packet(
258+
$this->packet_id++,
259+
1049,
260+
'42000',
261+
sprintf( "Unknown database: '%s'", $database )
262+
);
263+
}
264+
}
254265
}
255266

256267
// Get the authentication plugin name.

0 commit comments

Comments
 (0)