PDO database class review I've taken this class and made it my own but I'm curious to know what other think of it? Are there things I'm missing? Anything you can recommend?

class Database {
    private $host = '';
    private $user = '';
    private $pass = '';
    private $dbname = '';

    private $dbh;
    private $error;
    private $stmt;

    public function __construct() {
        $dsn = 'mysql:dbname=' . $this -&gt; dbname . ';host=' . $this -&gt; host . '';
        // Set options
        $options = array(PDO::ATTR_PERSISTENT =&gt; true, PDO::ATTR_ERRMODE =&gt; PDO::ERRMODE_EXCEPTION);
        // Create a new PDO instanace
        try {
            $this -&gt; dbh = new PDO($dsn, $this -&gt; user, $this -&gt; pass, $options);
        } catch(PDOException $e) {
            $this-&gt;error = $e -&gt; getMessage();
        }
    }

    public function query($query) {
        $this -&gt; stmt = $this -&gt; dbh -&gt; prepare($query);
    }

    public function bind($param, $value, $type = null) {
        if (is_null($type)) {
            switch (true) {
                case is_int($value) :
                    $type = PDO::PARAM_INT;
                    break;
                case is_bool($value) :
                    $type = PDO::PARAM_BOOL;
                    break;
                case is_null($value) :
                    $type = PDO::PARAM_NULL;
                    break;
                default :
                    $type = PDO::PARAM_STR;
            }
        }
        $this -&gt; stmt -&gt; bindValue($param, $value, $type);
    }

    public function execute() {
        return $this -&gt; stmt -&gt; execute();
    }

    public function fetchAll() {
        $this -&gt; execute();
        return $this -&gt; stmt -&gt; fetchAll(PDO::FETCH_ASSOC);
    }

    public function fetch() {
        $this -&gt; execute();
        return $this -&gt; stmt -&gt; fetch(PDO::FETCH_ASSOC);
    }

    public function rowCount() {
        return $this -&gt; stmt -&gt; rowCount();
    }

    public function countAll($arr) {
        return count($arr);
    }

    public function lastInsertId() {
        return $this -&gt; dbh -&gt; lastInsertId();
    }
}
I have set up something very similar with a couple changes. In __contruct() I assign the credentials to variables, then call an instance to start the PDO connection. I also use try-catch for each PDO statement to make sure that I am not getting any errors.

private $_pdo = null;
private $_host, $_dbname, $_uname, $_pass;
private $_sql, $_result;
private $_preparedStmt;

public function __construct($host, $dbname, $username, $password) {
    // You could run checks here to make sure that...
    // no values or specific values are not equal to ''
    $this-&gt;_host = $host;
    $this-&gt;_dbname = $dbname;
    $this-&gt;_uname = $username;
    $this-&gt;_pass = $password;
    $this-&gt;startPDO();
}

// ... Later on in code, under Private functions comment tag
private function startPDO() {
    try {
        $this-&gt;_pdo = new PDO('mysql:host='.$this-&gt;_host.';dbname='.$this-&gt;_dbname, $this-&gt;_uname, $this-&gt;_pass);
        $this-&gt;_pdo-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    } catch (PDOException $e) {
        //$this-&gt;handleFatalErr($e-&gt;getMessage(), 'connection'); // 'die' error handling
        //$this-&gt;handleErr($e-&gt;getMessage(), 'connection'); // Non-'die' error handling
    }
}


In each function I check the connection, I would recommend something similar. You could either kill the script if there is no connection or you could re-connect using the current variables $this-&gt;_host, etc:

public function query($sql) {
    $this-&gt;checkConnection();
    $this-&gt;_sql = $sql; // This is used for logging and for a getter function
    try {
        $this-&gt;_result = $this-&gt;_pdo-&gt;query($this-&gt;_sql);
    } catch (PDOException $e) {
        //$this-&gt;handleFatalErr($e-&gt;getMessage(), 'connection');
    }
}

private function checkConnection() {
    ($this-&gt;getPDO() === null) ? die('There is no connection to the database, please re-establish connection.') : NULL;
        //$this-&gt;handleFatalErr(self::ERR_CONNECTION_LOST, 'CONNECTION_LOST');
}

private function getPDO() {
    return $this-&gt;_pdo;
}

public function close() {
    (isset($this-&gt;_pdo) &amp;&amp; $this-&gt;_pdo != null) ? $this-&gt;_pdo = null : NULL;
}