This is damn ugly patch if you need to update it, see PHP_5_2 branch version to understand what this patch is supposed to do as in 5.3 the ini section is enabled only if mysqlnd driver is enabled which makes the contexts really small. diff -urNp -x '*.orig' php-5.6.40.org/ext/pdo_mysql/mysql_driver.c php-5.6.40/ext/pdo_mysql/mysql_driver.c --- php-5.6.40.org/ext/pdo_mysql/mysql_driver.c 2019-01-09 10:54:13.000000000 +0100 +++ php-5.6.40/ext/pdo_mysql/mysql_driver.c 2021-08-23 23:19:43.115775250 +0200 @@ -539,6 +539,7 @@ static int pdo_mysql_handle_factory(pdo_ pdo_mysql_db_handle *H; int i, ret = 0; char *host = NULL, *unix_socket = NULL; + char *connect_charset = NULL; unsigned int port = 3306; char *dbname; struct pdo_data_src_parser vars[] = { @@ -764,6 +765,12 @@ static int pdo_mysql_handle_factory(pdo_ password_len = strlen(dbh->password); } + connect_charset = PDO_MYSQL_G(connect_charset); + + if (connect_charset != NULL) { + mysql_options(H->server, MYSQL_SET_CHARSET_NAME, connect_charset); + } + if (mysqlnd_connect(H->server, host, dbh->username, dbh->password, password_len, dbname, dbname_len, port, unix_socket, connect_opts, MYSQLND_CLIENT_NO_FLAG TSRMLS_CC) == NULL) { #else diff -urNp -x '*.orig' php-5.6.40.org/ext/pdo_mysql/pdo_mysql.c php-5.6.40/ext/pdo_mysql/pdo_mysql.c --- php-5.6.40.org/ext/pdo_mysql/pdo_mysql.c 2019-01-09 10:54:13.000000000 +0100 +++ php-5.6.40/ext/pdo_mysql/pdo_mysql.c 2021-08-23 23:19:43.115775250 +0200 @@ -95,6 +95,7 @@ PHP_INI_BEGIN() #if PDO_DBG_ENABLED STD_PHP_INI_ENTRY("pdo_mysql.debug", NULL, PHP_INI_SYSTEM, OnUpdateString, debug, zend_pdo_mysql_globals, pdo_mysql_globals) #endif + STD_PHP_INI_ENTRY("pdo_mysql.connect_charset", NULL, PHP_INI_ALL, OnUpdateString, connect_charset, zend_pdo_mysql_globals, pdo_mysql_globals) PHP_INI_END() /* }}} */ @@ -141,9 +142,7 @@ static PHP_MINIT_FUNCTION(pdo_mysql) static PHP_MSHUTDOWN_FUNCTION(pdo_mysql) { php_pdo_unregister_driver(&pdo_mysql_driver); -#if PDO_USE_MYSQLND UNREGISTER_INI_ENTRIES(); -#endif return SUCCESS; } @@ -213,6 +212,7 @@ static PHP_GINIT_FUNCTION(pdo_mysql) pdo_mysql_globals->debug = NULL; /* The actual string */ pdo_mysql_globals->dbg = NULL; /* The DBG object*/ #endif + pdo_mysql_globals->connect_charset = NULL; } /* }}} */ diff -urNp -x '*.orig' php-5.6.40.org/ext/pdo_mysql/php_pdo_mysql_int.h php-5.6.40/ext/pdo_mysql/php_pdo_mysql_int.h --- php-5.6.40.org/ext/pdo_mysql/php_pdo_mysql_int.h 2019-01-09 10:54:13.000000000 +0100 +++ php-5.6.40/ext/pdo_mysql/php_pdo_mysql_int.h 2021-08-23 23:19:43.115775250 +0200 @@ -72,6 +72,7 @@ ZEND_BEGIN_MODULE_GLOBALS(pdo_mysql) char *debug; /* The actual string */ MYSQLND_DEBUG *dbg; /* The DBG object */ #endif + char *connect_charset; #if defined(PHP_WIN32) && !PDO_DBG_ENABLED /* dummy member so we get at least one member in the struct * and avoids build errors.