调用未定义的方法Closure :: query() [英] Call to undefined method Closure::query()
本文介绍了调用未定义的方法Closure :: query()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下终止语
$dbhProvider = function (){
//Create connection.
$instance = new \mysqli('localhost', USERNAME, PASSWORD, 'BLOG');
return $instance;
};
我有以下实现方式
$mapper = new UserMapper($dbhProvider);
UserMapper
的 __ constructor
看起来像这样
public function __construct($connection){
$this->connection = $connection;
$sql = 'SELECT * FROM USERS WHERE ID=' . $this->user->getId();
$result = $this->connection->query($sql);
}
当我执行时,出现以下错误调用未定义的方法Closure :: query()
.我该如何正确实现,以使 $ this-> connection
实例变量包含 mysqli
连接?
And when i exexute i have the following error
Call to undefined method Closure::query()
. How can i do the properly implement so that the $this->connection
instance variable holds the mysqli
connection?
推荐答案
public function __construct($provider) {
// invoke the closure/provider/factory
// so that it returns the mysqli instance
// which then gets assigned to $this->connection
$this->connection = $provider();
$sql = 'SELECT * FROM USERS WHERE ID=' ....
}
这篇关于调用未定义的方法Closure :: query()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文