PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular

mysqli_real_escape_string

Tags: PHP 5.x PHP 7.x PHP 8.x

mysqli_real_escape_string — Escapes special characters in a string for use in an SQL statement, taking into account the current charset of the connection.

Description

mysqli_real_escape_string(
    mysqli $mysql, string $string
): string
This function is used to create a legal SQL string that you can use in an SQL statement. The given string is encoded to produce an escaped SQL string, taking into account the current character set of the connection.

Parameters

A mysqli_result object returned by mysqli_query(), mysqli_store_result(), mysqli_use_result() or mysqli_stmt_get_result().

mysql
Procedural style only: A mysqli object returned by mysqli_connect() or mysqli_init()
string
The string to be escaped. Characters encoded are NUL (ASCII 0), \n, \r, \, ', ", and Control-Z.

Return Values

Returns an escaped string.