mirror of
https://github.com/php/php-src.git
synced 2024-12-01 13:54:10 +08:00
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.
This commit is contained in:
parent
1d9c49bb3c
commit
83051b1a86
@ -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;
|
||||
}
|
||||
|
@ -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 <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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user