downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

mysql_fetch_array> <mysql_error
[edit] Last updated: Fri, 25 May 2012

view this page in

mysql_escape_string

(PHP 4 >= 4.0.3, PHP 5)

mysql_escape_stringmysql_query で使用するために文字列をエスケープする

説明

string mysql_escape_string ( string $unescaped_string )

この関数は、mysql_query() で指定可能なように unescaped_string をエスケープします。 この関数は非推奨です。

この関数は mysql_real_escape_string() とほぼ同じです。ただ mysql_real_escape_string() はコネクションハンドラを用い、 カレントの文字セットを考慮したエスケープを行うという点が違います。 mysql_escape_string() はコネクションに関する引数を 持たず、カレントの文字セット設定を考慮しません。

警告

この関数は PHP 5.3.0 で 非推奨となりました。 この機能を使用しないことを強く推奨します。

パラメータ

unescaped_string

エスケープされる文字列。

返り値

エスケープされた文字列を返します。

変更履歴

バージョン 説明
5.3.0 この関数は E_DEPRECATED をスローするようになりました。
4.3.0 この関数は非推奨となりました。利用しないでください。代わりに mysql_real_escape_string() を利用してください。

例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

注意

注意: 代替策について

この拡張モジュールを使うことはおすすめできません。 MySQLi あるいは PDO_MySQL を使うべきです。詳細な情報は MySQL: API の選択 を参照ください。

この関数の代替として、これらが使えます。

注意:

mysql_escape_string() は、 % および _ をエスケープしません。

参考



add a note add a note User Contributed Notes mysql_escape_string
s dot marechal at jejik dot com 26-Jan-2011 02:37
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).
as_lh 26-Mar-2010 05:05
it seems the function changes the character encoding of the string.
I get utf-8 encoded string and my mysql database is set to utf-8 as well.
If i just write the data to the database it works perfectly fine, if i use this function, it changes the encoding and therefore stores the wrong characters.

Seems like a bug to me.

 
show source | credits | stats | sitemap | contact | advertising | mirror sites