From 83051b1a8650916db1f0872e5abddc80622e9446 Mon Sep 17 00:00:00 2001 From: Andrey Hristov Date: Mon, 14 Jun 2010 18:19:13 +0000 Subject: [PATCH] And a fix for MySQL Server which is pre 5.1.23, which doesn't support preserving of the charset when performing change_user. This is libmysql only code. --- ext/mysqli/mysqli_api.c | 17 ++++++++++++++++ ext/mysqli/php_mysqli_structs.h | 36 +++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/ext/mysqli/mysqli_api.c b/ext/mysqli/mysqli_api.c index fc3a72e49b..bb19f665ce 100644 --- a/ext/mysqli/mysqli_api.c +++ b/ext/mysqli/mysqli_api.c @@ -521,18 +521,35 @@ PHP_FUNCTION(mysqli_change_user) char *user, *password, *dbname; int user_len, password_len, dbname_len; ulong rc; +#if !defined(MYSQLI_USE_MYSQLND) && defined(HAVE_MYSQLI_SET_CHARSET) + const CHARSET_INFO * old_charset; +#endif if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Osss", &mysql_link, mysqli_link_class_entry, &user, &user_len, &password, &password_len, &dbname, &dbname_len) == FAILURE) { return; } MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID); +#if !defined(MYSQLI_USE_MYSQLND) && defined(HAVE_MYSQLI_SET_CHARSET) + old_charset = mysql->mysql->charset; +#endif + rc = mysql_change_user(mysql->mysql, user, password, dbname); MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql); if (rc) { RETURN_FALSE; } +#if !defined(MYSQLI_USE_MYSQLND) && defined(HAVE_MYSQLI_SET_CHARSET) + if (mysql_get_server_version(mysql->mysql) < 501023L) { + /* + Request the current charset, or it will be reset to the system one. + 5.0 doesn't support it. Support added in 5.1.23 by fixing the following bug : + Bug #30472 libmysql doesn't reset charset, insert_id after succ. mysql_change_user() call + */ + rc = mysql_set_character_set(mysql->mysql, old_charset->csname); + } +#endif RETURN_TRUE; } diff --git a/ext/mysqli/php_mysqli_structs.h b/ext/mysqli/php_mysqli_structs.h index bcfa29e0bf..41d14f2002 100644 --- a/ext/mysqli/php_mysqli_structs.h +++ b/ext/mysqli/php_mysqli_structs.h @@ -40,8 +40,44 @@ #include "ext/mysqlnd/mysqlnd.h" #include "mysqli_mysqlnd.h" #else + +/* + The libmysql headers (a PITA) also define it and there will be an warning. + Undef it and later we might need to define it again. +*/ +#ifdef HAVE_MBRLEN +#undef HAVE_MBRLEN +#define WE_HAD_MBRLEN +#endif +#ifdef HAVE_MBSTATE_T +#undef HAVE_MBSTATE_T +#define WE_HAD_MBSTATE_T +#endif + +#include + +#if !defined(HAVE_MBRLEN) && defined(WE_HAD_MBRLEN) +#define HAVE_MBRLEN 1 +#endif + +#if !defined(HAVE_MBSTATE_T) && defined(WE_HAD_MBSTATE_T) +#define HAVE_MBSTATE_T 1 +#endif + +/* + We need more than mysql.h because we need CHARSET_INFO in one place. + This order has been borrowed from the ODBC driver. Nothing can be removed + from the list of headers :( +*/ + +#include #include #include +#include +#include +#include +#include +#include #include "mysqli_libmysql.h" #endif -- 2.40.0