Warning: include_once(): http:// wrapper is disabled in the server configuration by allow_url_include=0 in /home/users/2/moriya-h5/web/confrage/php/sql/mysql_real_escape_string/mysql_real_escape_string.php on line 2

Warning: include_once(http://www.confrage.com/bin/header.php): failed to open stream: no suitable wrapper could be found in /home/users/2/moriya-h5/web/confrage/php/sql/mysql_real_escape_string/mysql_real_escape_string.php on line 2

Warning: include_once(): Failed opening 'http://www.confrage.com/bin/header.php' for inclusion (include_path='.:/usr/local/php/7.4/lib/php') in /home/users/2/moriya-h5/web/confrage/php/sql/mysql_real_escape_string/mysql_real_escape_string.php on line 2
mysql_real_escape_string

Warning: include_once(/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/menu.php): failed to open stream: No such file or directory in /home/users/2/moriya-h5/web/confrage/php/sql/mysql_real_escape_string/mysql_real_escape_string.php on line 27

Warning: include_once(): Failed opening '/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/menu.php' for inclusion (include_path='.:/usr/local/php/7.4/lib/php') in /home/users/2/moriya-h5/web/confrage/php/sql/mysql_real_escape_string/mysql_real_escape_string.php on line 27
 
トップページ >  PHP >  mysql_real_escape_string
初版2008/11/21: 最終更新日2012/09/07
mysql_real_escape_string
目次
mysql_real_escape_string
サンプルコード
サンプル
mysql_real_escape_string
SQL文中で用いる文字列の特殊文字をエスケープします。
mysql_real_escape_string関数は、現在の接続の文字コーディングを考慮してくれます。
ただし、「%」、「_」はエスケープしません。

以下がサンプルになります。

サンプルコード
(php部)
<?php
// 元の文字列
$string = "Let's Go!";
print "元の文字列";
print "$string";

// MySQLサーバーへの接続
$db=mysql_connect('mysql_host','mysql_user','mysql_password');

if(!is_resource($db)){
	print "MySQLサーバーへの接続失敗";
	exit();
}

// エスケープ後の文字列
$string_escape = mysql_real_escape_string($string);
print "エスケープ後の文字列";
print "$string_escape";
?>
サンプル
元の文字列
Let's Go!


Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /home/users/2/moriya-h5/web/confrage/php/sql/mysql_real_escape_string/mysql_real_escape_string.php:107 Stack trace: #0 {main} thrown in /home/users/2/moriya-h5/web/confrage/php/sql/mysql_real_escape_string/mysql_real_escape_string.php on line 107