I create a Mysql connection array and pass it to a connect method as such:

```
 $database->connect(array(ROOT_DB_HOST, 
        ROOT_DB_NAME, ROOT_DB_USERNAME, ROOT_DB_PASSWORD));

```

When I `print_r()` the array inside the connect method I get what I expect:

```
Array
(
    [0] => localhost
    [1] => dbname
    [2] => dbuser
    [3] => dbpass
)

```

However, inside the connect method I pass the array values to the DSN string and I received and undefined offset on 0,1,2,3. Here is the DSN string:

```
$this->dbh = new PDO('mysql:host='. $connection[0] .';dbname=' . $connection[1],     $connection[2], $connection[3]);

```

So I pass the values as an array and plug them into the PDO constructor and receive the errors, I don't know what is going on, any ideas?

Method:

```
public function connect($connection) {
    try {
        $this->dbh = new PDO('mysql:host='. $connection[0] .';dbname=' .  $connection[1], $connection[2], $connection[3]);
        $this->dbh->setAttribute(PDO::ATTR_ERRMODE,  PDO::ERRMODE_EXCEPTION);
        $this->dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
    } catch(PDOException $e) {
        throw new Exception($e->getMessage());
    }
}

```

Error:

> 
> Notice: Undefined offset: 0 in database.class.php on line 16 Notice:
> Undefined offset: 1 in database.class.php on line 16 Notice:
> Undefined offset: 2 in database.class.php on line 16 Notice: Undefined
> offset: 3 in database.class.php on line 16
> 
> 
> Fatal error: Uncaught
> exception 'Exception' with message 'SQLSTATE[28000] [1045] Access
> denied for user 'apache'@'localhost' (using password: NO)' in
> database.class.php:20 Stack trace: #0 sandboxx.php(16):
> Database->connect(Array) #1 {main} thrown in database.class.php on
> line 200
> 
> 
>