I have the following Closure
$dbhProvider = function (){
//Create connection.
$instance = new \mysqli('localhost', USERNAME, PASSWORD, 'BLOG');
return $instance;
};
And i have the following implementation
$mapper = new UserMapper($dbhProvider);
The __constructor of UserMapper looks like this
public function __construct($connection){
$this->connection = $connection;
$sql = 'SELECT * FROM USERS WHERE ID=' . $this->user->getId();
$result = $this->connection->query($sql);
}
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=' ....
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With