49 lines
1.2 KiB
PHP
49 lines
1.2 KiB
PHP
<?php
|
|
namespace App\Library;
|
|
|
|
class DatabaseConfig
|
|
{
|
|
private string $driver;
|
|
private string $host;
|
|
private string $dbname;
|
|
private string $port;
|
|
private string $charset;
|
|
private string $username;
|
|
private string $password;
|
|
|
|
public function __construct(string $db)
|
|
{
|
|
$envVars = parse_ini_file('.env', true);
|
|
$db = strtoupper($db);
|
|
foreach ($envVars as $dbname => $dbconfig) {
|
|
if ($dbname == $db) {
|
|
$config = $dbconfig;
|
|
}
|
|
}
|
|
$this->driver = $config['DB_DRIVER'];
|
|
$this->host = $config['DB_HOST'];
|
|
$this->dbname = $config['DB_NAME'];
|
|
$this->port = $config['DB_PORT'];
|
|
$this->charset = $config["DB_CHARSET"];
|
|
$this->username = $config['DB_USERNAME'];
|
|
$this->password = $config['DB_PASSWORD'];
|
|
}
|
|
|
|
public function getDsn() : string
|
|
{
|
|
return $this->driver.":host=".$this->host
|
|
.";dbname=".$this->dbname
|
|
.";charset=".$this->charset
|
|
.";port=".$this->port;
|
|
}
|
|
|
|
public function getUsername() : string
|
|
{
|
|
return $this->username;
|
|
}
|
|
|
|
public function getPassword() : string
|
|
{
|
|
return $this->password;
|
|
}
|
|
} |