PHP 手冊
上一頁 |  | 下一頁

# mysql_real_escape_string

(PHP 4 >= 4.3.0, PHP 5)

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

## Description

string mysql_real_escape_string ( string unescaped_string [, resource link_identifier])

This function will escape special characters in the unescaped_string, taking into account the current charset of the connection so that it is safe to place it in a mysql_query().

> 備注: mysql_real_escape_string() does not escape % and _.

示範 1.mysql_real_escape_string() example
`<?php $link = mysql_connect('localhost', 'mysql_user', 'mysql_password'); if (!$link) { die('Could not connect: ' . mysql_error()); } $item = "Zak's and Derick's Laptop"; $escaped_item = mysql_real_escape_string($item, $link); printf("Escaped string: %s\n", $escaped_item); ?>`
The above example would produce the following output:
    Escaped string: Zak\'s and Derick\'s Laptop

See also mysql_escape_string(), mysql_client_encoding(), addslashes(), and the magic_quotes_gpc directive.

上一頁 | 最開頭 | 下一頁
mysql_query | 上一層 | mysql_result