]> granicus.if.org Git - php/commitdiff
And a fix for MySQL Server which is pre 5.1.23, which doesn't support
authorAndrey Hristov <andrey@php.net>
Mon, 14 Jun 2010 18:19:13 +0000 (18:19 +0000)
committerAndrey Hristov <andrey@php.net>
Mon, 14 Jun 2010 18:19:13 +0000 (18:19 +0000)
preserving of the charset when performing change_user. This is libmysql
only code.

ext/mysqli/mysqli_api.c
ext/mysqli/php_mysqli_structs.h

index fc3a72e49b9ff5eea80d32d28721a67fefda03e7..bb19f665ceb5ad7c1a6fab209868af6d9f6c821c 100644 (file)
@@ -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;
 }
index bcfa29e0bf77e47b562fe5fd7017f2bcb6f98442..41d14f2002752f9cc2c9f0ba7d07d0dd8f08dcba 100644 (file)
 #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