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

search for in the

mysql_fetch_array> <mysql_error
[edit] Last updated: Fri, 17 May 2013

view this page in

mysql_escape_string

(PHP 4 >= 4.0.3, PHP 5)

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

警告

この拡張モジュールは PHP 5.5.0 で非推奨になりました。将来のバージョンで削除される予定です。 MySQLi あるいは PDO_MySQL を使うべきです。詳細な情報は MySQL: API の選択それに関連する FAQ を参照ください。 この関数の代替として、これらが使えます。

説明

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

注意

注意:

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

参考



add a note add a note User Contributed Notes mysql_escape_string - [2 notes]
up
0
as_lh
3 years ago
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.
up
-1
s dot marechal at jejik dot com
2 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).

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