I have a class that deals with a number of database operations. I want the class to be as re-usable and well-designed as possible, and I'm fairly new to OOP, so I would appreciate a solution to this:
Is it better practice to do:
class MyDatabase extends Database
{
private $connection;
public function __construct(mysqli $connection)
{
$this->connection=$connection;
}
//More functions below
}
or
class MyDatabase extends Database
{
private $connection;
public function __construct()
{
$this->connection=new mysqli(...);
}
//More functions below
}
What are the pros/cons of both, and which one is used more often? I can't really decide for myself which one I should start using, and it will affect the rest of the application I'm writing.
Thank you