Php OOP real\u escape\u字符串
我对mysqli\u real\u escape\u字符串有问题,我正在尝试所有操作,但仍然给我一个错误: “致命错误:调用未定义的方法数据库::real\u escape\u string()” 我的代码: 第一个文件:Php OOP real\u escape\u字符串,php,oop,mysqli,Php,Oop,Mysqli,我对mysqli\u real\u escape\u字符串有问题,我正在尝试所有操作,但仍然给我一个错误: “致命错误:调用未定义的方法数据库::real\u escape\u string()” 我的代码: 第一个文件: $Database = new Database($host,$user,$pass,$db); $Form = new Form($Database); echo $Form->GET('key'); 第二个文件: $Database = new Database(
$Database = new Database($host,$user,$pass,$db);
$Form = new Form($Database);
echo $Form->GET('key');
第二个文件:
$Database = new Database($host,$user,$pass,$db);
$Form = new Form($Database);
echo $Form->GET('key');
数据库:
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;
}
}
正如您在construct中看到的,我保存了mysqli连接,但我真的不知道为什么它不知道什么是真实的\u escape问题是
function __construct($con){
$this->mysqli = $con;
}
接受的不是类mysqli的对象
,而是类数据库的对象
,它具有属性连接
,它是类mysqli的对象
。
因此,适当的呼吁应该是:
function GET($string) {
return $this->mysqli->connection->real_escape_string($string);
}
虽然我不确定
$this->mysqli->connection->
是否能正确解析。escape\u string()
!=real\u escape\u string()
错误消息与代码不匹配。我们也不知道什么是数据库
意味着没有人能回答他的问题。所有这些看起来都很没有方向性。很有可能您在数据库
类和表单
中两次包装了->mysqli
。现在您已经发布了数据库
类并看到了错误消息,应该很清楚了。类数据库中没有名为real\u escape\u string
的方法谢谢