bindAPI/bindAPI/src/Controller/DatabaseConnection.php

38 lines
576 B
PHP
Raw Normal View History

2022-01-18 19:14:24 +01:00
<?php
namespace App\Controller;
use PDO;
use PDOException;
/**
*
*/
class DatabaseConnection
{
private PDO $dbConnection;
2022-01-22 14:27:09 +01:00
public function __construct(private array $config)
2022-01-18 19:14:24 +01:00
{
2022-01-22 14:27:09 +01:00
extract($this->config);
2022-01-18 19:14:24 +01:00
try {
$this->dbConnection = new PDO(
dsn: "mysql:host=$dbHost;port=$dbPort;charset=utf8mb4;dbname=$dbDatabase",
username: $dbUser,
password: $dbPassword
);
} catch (PDOException $exception) {
exit($exception->getMessage());
}
}
/**
* @return \PDO
*/
public function getConnection(): PDO
{
return $this->dbConnection;
}
}