Skip to content

Commit 489438f

Browse files
committed
Fixed handshake response charset.
1 parent 2f60582 commit 489438f

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

ext/mysqlnd/mysqlnd_charset.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
#ifndef MYSQLND_CHARSET_H
2020
#define MYSQLND_CHARSET_H
2121

22+
#define MYSQLND_UTF8_MB3_DEFAULT_ID 33
23+
#define MYSQLND_UTF8_MB4_DEFAULT_ID 45
24+
2225
PHPAPI zend_ulong mysqlnd_cset_escape_quotes(const MYSQLND_CHARSET * const charset, char * newstr,
2326
const char * escapestr, const size_t escapestr_len);
2427

ext/mysqlnd/mysqlnd_commands.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "mysqlnd_auth.h"
2323
#include "mysqlnd_wireprotocol.h"
2424
#include "mysqlnd_debug.h"
25+
#include "mysqlnd_charset.h"
2526

2627

2728
/* {{{ mysqlnd_command::set_option */
@@ -642,13 +643,12 @@ MYSQLND_METHOD(mysqlnd_command, handshake)(MYSQLND_CONN_DATA * const conn, const
642643
conn->protocol_version = greet_packet.protocol_version;
643644
conn->server_version = mnd_pestrdup(greet_packet.server_version, conn->persistent);
644645

645-
conn->greet_charset = mysqlnd_find_charset_nr(greet_packet.charset_no);
646-
if (!conn->greet_charset) {
647-
char * msg;
648-
mnd_sprintf(&msg, 0, "Server sent charset (%d) unknown to the client. Please, report to the developers", greet_packet.charset_no);
649-
SET_CLIENT_ERROR(conn->error_info, CR_NOT_IMPLEMENTED, UNKNOWN_SQLSTATE, msg);
650-
mnd_sprintf_free(msg);
651-
goto err;
646+
const MYSQLND_CHARSET *read_charset = mysqlnd_find_charset_nr(greet_packet.charset_no);
647+
if (!read_charset) {
648+
greet_packet.charset_no = conn->m->get_server_version(conn) >= 50500 ? MYSQLND_UTF8_MB4_DEFAULT_ID : MYSQLND_UTF8_MB3_DEFAULT_ID;
649+
conn->greet_charset = mysqlnd_find_charset_nr(greet_packet.charset_no);
650+
} else {
651+
conn->greet_charset = read_charset;
652652
}
653653

654654
conn->server_capabilities = greet_packet.server_capabilities;

0 commit comments

Comments
 (0)