Instantiating a Database connection class in PHP I am building my own MVC and I have a couple questions about making a database connection and what is the best practice. I have a model User which interacts with the database and I wonder what is the best practice to instantiate the database connection class. Currently I made it so my User class extends the Database class because I don't feel like instantiating it in a constructor for example.  

class User extends Database
{    

    public function data($userid)
    {        
        $getRow = $this-&gt;getConnect()-&gt;getRow("SELECT * FROM users WHERE userid = ?", [$userid]);

        return $getRow;
    }

}


And my Database class:

class Database
{

    private $dbh = NULL;
    private $instance = NULL;

    public function __construct($username = 'root', $password = '', $host = '127.0.0.1', $dbname = 'testdb', $options = [])
    {
        try  {
            $this-&gt;dbh = new PDO("mysql:dbname={$dbname};host={$host};charset=utf8", $username, $password);
            $this-&gt;dbh-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            $this-&gt;dbh-&gt;setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
        } catch (PDOException $ex) {
            throw new Exception($ex-&gt;getMessage());
        }

    }

    public function getConnect()
    {
        if($this-&gt;instance == NULL)
        {
            $this-&gt;instance = new self();
        }
        return $this-&gt;instance;
    }
}


Also, my getConnect method seems kinda hard coding. Do you think there is a smarter way to do this?

And one more thing, about public/private if anything is better to be private, I'd appreciate if you let me know.
Is a "user" a "database"?

That doesn't sound right.
A database is a tool or service that provides fast access to data via queries,
and a user sounds like a representation of a real-life user,
described by a set of characteristics.
A representation of a user may use a database to store its data,
but it is not a database.

In short, User should not extend Database.
A User could be a container for user data,
and User instances could be created by a UserFactory or UserRepository which could be implemented to fetch the user data from a database or some other backend.

Getting fields from a database

Instead of SELECT * queries,
it's recommended to name the required fields explicitly.
This can reduce the amount of data transferred from the database,
and it eliminates dependence on the ordering of columns.

What is getConnect ?

The getConnect function returns the Database singleton instance,
not a "connect".
Getting a "connect" seems meaningless.
getInstance is a more common name in singleton implementations.

public or private

As a good rule of thumb,
make everything private,
and then change some of them public as necessary.

The less implementation details are visible, the better.
Implementation details that are not visible give you the flexibility to change those details without affecting the users.