运行 mysql_real_escape_string($value) 时出现此错误。
Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Can't connect to MySQL server on 'localhost' (10061) in ...
我将功能包装在一个像这样的好类中
class escaper
{
function __get($value)
{
//in order for this to work properly, I must have a live connection to mysql
return mysql_real_escape_string($value);
}
}
/*
//sample usage
$safe = new escaper;
$name = "O'Reilly";
echo $safe->$name
万一有人再次走上那条路,让我提前说是的!我应该使用 PDO 和参数化查询,并且上述方法不是那么安全。