public function connect($pHost, $pDb, $pUser = NULL, $pPass = NULL)
    {
        try {
            if ($pUser !== NULL and $pPass !== NULL and is_string($pUser) and is_string($pPass)) {
                $connection = new PDO("mysql:host=$pHost;dbname=$pDb", $pUser, $pPass);
            } else {
                $connection = new PDO("mysql:host=$pHost;dbname=$pDb");
            }
        } catch(PDOException $e) {
            throw new Exception("Unable to establish a connection to MySQL: Host '$pHost', DB '$pDb', User '$pUser', Password '$pPass' with message '" . $e->getMessage() . "'");
        }

        $connection->query("SET NAMES 'utf8';");

        return $connection;
    }