Skip to content

Commit e6dc9ab

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Support NO_BACKSLASH_ESCAPES with newer libmysqlclient
2 parents d87c393 + 70cba36 commit e6dc9ab

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

ext/mysqli/mysqli_api.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1941,6 +1941,11 @@ PHP_FUNCTION(mysqli_real_query)
19411941
}
19421942
/* }}} */
19431943

1944+
#if defined(PDO_USE_MYSQLND) || MYSQL_VERSION_ID < 50707 || defined(MARIADB_BASE_VERSION)
1945+
# define mysql_real_escape_string_quote(mysql, to, from, length, quote) \
1946+
mysql_real_escape_string(mysql, to, from, length)
1947+
#endif
1948+
19441949
/* {{{ proto string mysqli_real_escape_string(object link, string escapestr)
19451950
Escapes special characters in a string for use in a SQL statement, taking into account the current charset of the connection */
19461951
PHP_FUNCTION(mysqli_real_escape_string) {
@@ -1956,7 +1961,7 @@ PHP_FUNCTION(mysqli_real_escape_string) {
19561961
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
19571962

19581963
newstr = zend_string_alloc(2 * escapestr_len, 0);
1959-
ZSTR_LEN(newstr) = mysql_real_escape_string(mysql->mysql, ZSTR_VAL(newstr), escapestr, escapestr_len);
1964+
ZSTR_LEN(newstr) = mysql_real_escape_string_quote(mysql->mysql, ZSTR_VAL(newstr), escapestr, escapestr_len, '\'');
19601965
newstr = zend_string_truncate(newstr, ZSTR_LEN(newstr), 0);
19611966

19621967
RETURN_NEW_STR(newstr);

ext/pdo_mysql/mysql_driver.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,11 @@ static char *pdo_mysql_last_insert_id(pdo_dbh_t *dbh, const char *name, size_t *
293293
}
294294
/* }}} */
295295

296+
#if defined(PDO_USE_MYSQLND) || MYSQL_VERSION_ID < 50707 || defined(MARIADB_BASE_VERSION)
297+
# define mysql_real_escape_string_quote(mysql, to, from, length, quote) \
298+
mysql_real_escape_string(mysql, to, from, length)
299+
#endif
300+
296301
/* {{{ mysql_handle_quoter */
297302
static int mysql_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, size_t unquotedlen, char **quoted, size_t *quotedlen, enum pdo_param_type paramtype )
298303
{
@@ -315,13 +320,13 @@ static int mysql_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, size_t unqu
315320
*quoted = safe_emalloc(2, unquotedlen, 3 + (use_national_character_set ? 1 : 0));
316321

317322
if (use_national_character_set) {
318-
*quotedlen = mysql_real_escape_string(H->server, *quoted + 2, unquoted, unquotedlen);
323+
*quotedlen = mysql_real_escape_string_quote(H->server, *quoted + 2, unquoted, unquotedlen, '\'');
319324
(*quoted)[0] = 'N';
320325
(*quoted)[1] = '\'';
321326

322327
++*quotedlen; /* N prefix */
323328
} else {
324-
*quotedlen = mysql_real_escape_string(H->server, *quoted + 1, unquoted, unquotedlen);
329+
*quotedlen = mysql_real_escape_string_quote(H->server, *quoted + 1, unquoted, unquotedlen, '\'');
325330
(*quoted)[0] = '\'';
326331
}
327332

0 commit comments

Comments
 (0)