mysql_escape_string

(PHP 4 >= 4.0.3, PHP 5)

mysql_escape_stringmysql_query에서 문자열을 escape하기위해 사용

설명

string mysql_escape_string ( string $unescaped_string )

이 함수는 unescaped_stringmysql_query()에 안전하도록 escape시킨다. 이 함수의 사용은 권장하지 않는다.

이 함수는 접속 핸들러를 이용하여 현재 문자셋을 따라서 문자를 escape하는 것만 제외하고는 mysql_real_escape_string()와 비슷하다. mysql_escape_string()는 접속 핸들러를 인수로 갖지 않으며, 현재 문자셋에 대해 고려하지 않는다.

인수

unescaped_string

Escape할 문자열.

반환값

Escape된 문자열.

변경점

버전 설명
5.3.0 E_DEPRECATED 주의가 발생합니다.
4.3.0 이 함수의 사용은 권장하지 않는다. 대신, mysql_real_escape_string()를 사용하라.

예제

Example #1 mysql_escape_string() 예제

<?php
$item 
"Zak's Laptop";
$escaped_item mysql_escape_string($item);
printf("Escaped string: %s\n"$escaped_item);
?>

위 예제의 출력:

Escaped string: Zak\'s Laptop

주의

Note:

mysql_escape_string()%_를 escape하지 않는다.

참고

add a note add a note

User Contributed Notes 2 notes

up
8
PHPguru
9 years ago
You can use this function safely with your MySQL database queries if and only if you are sure that your database connection is using ASCII, UTF-8, or ISO-8859-* and that the backslash is your database's escape character. If you're not sure, then use mysqli_real_escape_string instead. This function is not safe to use on databases with multi-byte character sets.

The only benefit of this function is that it does not require a database connection.
up
-28
s dot marechal at jejik dot com
13 years ago
The exact characters that are escaped by this function are the null byte (0), newline (\n), carriage return (\r), backslash (\), single quote ('), double quote (") and substiture (SUB, or \032).
To Top