Skip to content

Commit 9962ad6

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Support NO_BACKSLASH_ESCAPES with newer libmysqlclient
2 parents 74d1699 + e6dc9ab commit 9962ad6

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

ext/mysqli/mysqli_api.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,7 +1885,11 @@ PHP_FUNCTION(mysqli_real_query)
18851885
}
18861886
/* }}} */
18871887

1888-
/* {{{ Escapes special characters in a string for use in a SQL statement, taking into account the current charset of the connection */
1888+
#if defined(PDO_USE_MYSQLND) || MYSQL_VERSION_ID < 50707 || defined(MARIADB_BASE_VERSION)
1889+
# define mysql_real_escape_string_quote(mysql, to, from, length, quote) \
1890+
mysql_real_escape_string(mysql, to, from, length)
1891+
#endif
1892+
18891893
PHP_FUNCTION(mysqli_real_escape_string) {
18901894
MY_MYSQL *mysql;
18911895
zval *mysql_link = NULL;
@@ -1899,12 +1903,11 @@ PHP_FUNCTION(mysqli_real_escape_string) {
18991903
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
19001904

19011905
newstr = zend_string_alloc(2 * escapestr_len, 0);
1902-
ZSTR_LEN(newstr) = mysql_real_escape_string(mysql->mysql, ZSTR_VAL(newstr), escapestr, escapestr_len);
1906+
ZSTR_LEN(newstr) = mysql_real_escape_string_quote(mysql->mysql, ZSTR_VAL(newstr), escapestr, escapestr_len, '\'');
19031907
newstr = zend_string_truncate(newstr, ZSTR_LEN(newstr), 0);
19041908

19051909
RETURN_NEW_STR(newstr);
19061910
}
1907-
/* }}} */
19081911

19091912
/* {{{ Undo actions from current transaction */
19101913
PHP_FUNCTION(mysqli_rollback)

ext/pdo_mysql/mysql_driver.c

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

294+
#if defined(PDO_USE_MYSQLND) || MYSQL_VERSION_ID < 50707 || defined(MARIADB_BASE_VERSION)
295+
# define mysql_real_escape_string_quote(mysql, to, from, length, quote) \
296+
mysql_real_escape_string(mysql, to, from, length)
297+
#endif
298+
294299
/* {{{ mysql_handle_quoter */
295300
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 )
296301
{
@@ -313,13 +318,13 @@ static int mysql_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, size_t unqu
313318
*quoted = safe_emalloc(2, unquotedlen, 3 + (use_national_character_set ? 1 : 0));
314319

315320
if (use_national_character_set) {
316-
*quotedlen = mysql_real_escape_string(H->server, *quoted + 2, unquoted, unquotedlen);
321+
*quotedlen = mysql_real_escape_string_quote(H->server, *quoted + 2, unquoted, unquotedlen, '\'');
317322
(*quoted)[0] = 'N';
318323
(*quoted)[1] = '\'';
319324

320325
++*quotedlen; /* N prefix */
321326
} else {
322-
*quotedlen = mysql_real_escape_string(H->server, *quoted + 1, unquoted, unquotedlen);
327+
*quotedlen = mysql_real_escape_string_quote(H->server, *quoted + 1, unquoted, unquotedlen, '\'');
323328
(*quoted)[0] = '\'';
324329
}
325330

0 commit comments

Comments
 (0)