Skip to content

Commit 70cba36

Browse files
committed
Support NO_BACKSLASH_ESCAPES with newer libmysqlclient
Requires the use of mysql_real_escape_string_quote().
1 parent 77f43e4 commit 70cba36

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
@@ -1954,6 +1954,11 @@ PHP_FUNCTION(mysqli_real_query)
19541954
}
19551955
/* }}} */
19561956

1957+
#if defined(PDO_USE_MYSQLND) || MYSQL_VERSION_ID < 50707 || defined(MARIADB_BASE_VERSION)
1958+
# define mysql_real_escape_string_quote(mysql, to, from, length, quote) \
1959+
mysql_real_escape_string(mysql, to, from, length)
1960+
#endif
1961+
19571962
/* {{{ proto string mysqli_real_escape_string(object link, string escapestr)
19581963
Escapes special characters in a string for use in a SQL statement, taking into account the current charset of the connection */
19591964
PHP_FUNCTION(mysqli_real_escape_string) {
@@ -1969,7 +1974,7 @@ PHP_FUNCTION(mysqli_real_escape_string) {
19691974
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
19701975

19711976
newstr = zend_string_alloc(2 * escapestr_len, 0);
1972-
ZSTR_LEN(newstr) = mysql_real_escape_string(mysql->mysql, ZSTR_VAL(newstr), escapestr, escapestr_len);
1977+
ZSTR_LEN(newstr) = mysql_real_escape_string_quote(mysql->mysql, ZSTR_VAL(newstr), escapestr, escapestr_len, '\'');
19731978
newstr = zend_string_truncate(newstr, ZSTR_LEN(newstr), 0);
19741979

19751980
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)