【发布时间】:2015-07-18 18:42:01
【问题描述】:
我对 mysqli_real_escape_string 有问题,我正在尝试所有但它仍然给我一个错误:
“致命错误:调用未定义的方法 Database::real_escape_string()”
我的代码: 第一个文件:
$Database = new Database($host,$user,$pass,$db);
$Form = new Form($Database);
echo $Form->GET('key');
第二个文件:
class Form{
public $mysqli;
function __construct($con){
$this->mysqli = $con;
}
function GET($string) {
return $this->mysqli->real_escape_string($string);
}
}
数据库:
class Database {
public $connection;
public function __construct($host,$user,$pass,$db) {
$this->Connect($host,$user,$pass,$db);
}
function Connect($host,$user,$pass,$db) {
$this->connection = new mysqli($host,$user,$pass,$db);
return $this->connection;
}
}
正如你在构造中看到的那样,我已经保存了 mysqli 连接,但我真的不知道为什么它不知道什么是 real_escape
【问题讨论】:
-
escape_string()!=real_escape_string() -
您的错误信息与您的代码不匹配。我们也不知道
Database是什么意思没有人可以回答他的。 -
所有看起来都没有方向。很有可能您在
Database类和Form中包装了两次->mysqli。 -
现在您已经发布了您的
Database课程并且看到错误消息应该很清楚了。Database类中没有名为real_escape_string的方法。