I'm getting 'invalid data source name' when trying to concatenate the array in config.php. It works fine if I hardcode it what am I doing wrong here?
Thanks
config.php
<?php
return [
'database' => [
'host' => 'mysql:host=127.0.0.1',
'database' => 'pdo_database',
'username' => 'root',
'password' => '',
'options' => [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
]
]
];
connection.php
<?php
$config = require('config.php');
$database = $config['database'];
class Connection {
public function make() {
try {
return new PDO(
$database['host'].';dbname='.$database['database'],
$database['username'],
$database['password'],
$database['options']
);
} catch(PDOException $e) {
die($e->getMessage());
}
}
}