diff --git a/src/Service/DatabaseConnection.php b/src/Service/DatabaseConnection.php new file mode 100644 index 0000000..ff20ee7 --- /dev/null +++ b/src/Service/DatabaseConnection.php @@ -0,0 +1,38 @@ +<?php + +namespace App\Service; + +use PDO; +use PDOException; + +/** + * + */ +class DatabaseConnection +{ + private PDO $dbConnection; + + const TABLE_PREFIX = ''; + const TABLE_DOMAINS = self::TABLE_PREFIX . "users"; + const TABLE_NAMESERVERS = self::TABLE_PREFIX . "addresses"; + + public function __construct(private readonly ConfigController $configController) + { + $dbHost = $this->configController->getConfig(configKey: 'dbHost'); + $dbPort = $this->configController->getConfig(configKey: 'dbPort'); + $dbDatabase = $this->configController->getConfig(configKey: 'dbDatabase'); + $dbUser = $this->configController->getConfig(configKey: 'dbUser'); + $dbPassword = $this->configController->getConfig(configKey: 'dbPassword'); + + $this->dbConnection = new PDO( + dsn: "mysql:host=$dbHost;port=$dbPort;charset=utf8mb4;dbname=$dbDatabase", + username: $dbUser, + password: $dbPassword + ); + } + + public function getConnection(): PDO + { + return $this->dbConnection; + } +} \ No newline at end of file