mysql_real_escape_string()完全删除字符串

lee*_*d00 6 php mysql mysql-real-escape-string

我正在逃避从php表单收到的所有字符串参数,如下所示:

$usr_name = mysql_real_escape_string($_REQUEST['usr_name']);
Run Code Online (Sandbox Code Playgroud)

避免SQL注入的一些问题.但是当我从函数中恢复我的字符串时,我什么都没有结果.

另外,我在PHP日志中不断收到这个奇怪的警告:

PHP Warning:  mysql_real_escape_string() [<a href='function.mysql-real-escape-string'>function.mysql-real-escape-string</a>]: A link to the server could not be established in /hermes/bosweb/web279/b2798/ipw.bankingforms/public_html/formAckResponse_controller.php on line 39
Run Code Online (Sandbox Code Playgroud)

主机使用:PHP版本4.4.7

hbw*_*hbw 18

来自PHP.net:

注意:在使用之前需要MySQL连接, mysql_real_escape_string()否则E_WARNING会生成级别错误,并FALSE返回.如果 link_identifier未定义,则使用最后一个MySQL连接.

换句话说,您需要在使用此功能之前mysql_connect()mysql_pconnect()之前连接到MySQL数据库.

  • 它在服务器端运行,因为MySQL的转义取决于服务器当前使用的字符集. (2认同)