public function connect(array $config, $username = null, $password = null, array $options = array())
    {
        // Validate config
        if (! isset($config['host'], $config['database'])) {
            throw new DatabaseDriverException("No 'host' or 'database' given in the configuration of the connection!");
        }

        $port = isset($config['port']) ? $config['port'] : 3306;
        $charset = isset($config['charset']) ? $config['charset'] : 'utf8';

        // Prepare dsn.
        $dsn = "mysql:host={$config['host']};port=$port;dbname={$config['database']};charset=$charset";

        // Connect
        $connection = new Connection($dsn, $username, $password, $options);

        $connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);

        return $connection;
    }