summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/mysqli/mysqli_api.c17
-rw-r--r--ext/mysqli/php_mysqli_structs.h36
2 files changed, 53 insertions, 0 deletions
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 9c2433ec1b..4ab7adcba7 100644
--- a/ext/mysqli/php_mysqli_structs.h
+++ b/ext/mysqli/php_mysqli_structs.h
@@ -42,8 +42,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 <my_global.h>
+
+#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 <my_sys.h>
#include <mysql.h>
#include <errmsg.h>
+#include <my_list.h>
+#include <m_string.h>
+#include <mysqld_error.h>
+#include <my_list.h>
+#include <m_ctype.h>
#include "mysqli_libmysql.h"
#endif