简体   繁体   English

PHP mysql_real_escape_string 的问题

[英]Problem with PHP mysql_real_escape_string

When I run mysql_real_escape_string , for example like this:当我运行mysql_real_escape_string时,例如这样:

$test = mysql_real_escape_string($_POST['test']);

it's not working on local server, it gives me an error page!它在本地服务器上不起作用,它给了我一个错误页面!

  • my local server is " AppServ ".我的本地服务器是“ AppServ ”。
  • my operating systim is " windows XP ".我的操作系统是“ windows XP ”。

Is this normal?这是正常的吗? and just i have to run it on hosted site only !而且我只需要在托管站点上运行它!

You have to provide the function an active database connection.您必须为 function 提供活动数据库连接。 I think it's the second argument:我认为这是第二个论点:

$test = mysql_real_escape_string($_POST['test'], $mysql_database_connection);

That might be your error, because if you don't provide an active connection explicitly, the function looks for the last one which was created.这可能是您的错误,因为如果您没有明确提供活动连接,function 会查找最后一个创建的连接。 If you run this function before connecting to the database, it'll give you an error.如果你在连接数据库之前运行这个 function,它会给你一个错误。

We'd need to know which error before we could help you any more, but the most common error that I get when using mysql_real_escape_string is when I forget that it takes a second parameter .我们需要知道哪个错误才能为您提供更多帮助,但是我在使用mysql_real_escape_string时遇到的最常见错误是当我忘记它需要第二个参数时。

This tells the function which character set you need escaping.这告诉 function 您需要哪个字符集 escaping。 You just need to pass the database resource ID.您只需要传递数据库资源 ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM