我有以下关闭
$dbhProvider = function (){
//Create connection.
$instance = new \mysqli('localhost', USERNAME, PASSWORD, 'BLOG');
return $instance;
};
我有以下实现
$mapper = new UserMapper($dbhProvider);
The __constructor
of UserMapper
看起来像这样
public function __construct($connection){
$this->connection = $connection;
$sql = 'SELECT * FROM USERS WHERE ID=' . $this->user->getId();
$result = $this->connection->query($sql);
}
当我执行时出现以下错误Call to undefined method Closure::query()
。我怎样才能正确实施,以便$this->connection
实例变量保存mysqli
联系?
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=' ....
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)