From 2965e9b7ce95bb488621a9657ff51a530145e4f7 Mon Sep 17 00:00:00 2001 From: tracer Date: Sat, 8 Oct 2022 10:55:25 +0200 Subject: [PATCH] added options for testing --- src/Controller/DatabaseConnection.php | 39 ++++++++++++++------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/src/Controller/DatabaseConnection.php b/src/Controller/DatabaseConnection.php index f3beb43..8ec73ed 100644 --- a/src/Controller/DatabaseConnection.php +++ b/src/Controller/DatabaseConnection.php @@ -2,7 +2,7 @@ namespace App\Controller; -error_reporting(error_level: E_ALL); +//error_reporting(error_level: E_ALL); use PDO; @@ -15,31 +15,32 @@ class DatabaseConnection { private PDO $dbConnection; - const TABLE_PREFIX = ''; - const TABLE_DOMAINS = self::TABLE_PREFIX . "domains"; + const TABLE_PREFIX = ''; + const TABLE_DOMAINS = self::TABLE_PREFIX . "domains"; const TABLE_NAMESERVERS = self::TABLE_PREFIX . "nameservers"; - const TABLE_PANELS = self::TABLE_PREFIX . "panels"; - const TABLE_APIKEYS = self::TABLE_PREFIX . "apikeys"; - const TABLE_DYNDNS = self::TABLE_PREFIX . "dyndns"; + const TABLE_PANELS = self::TABLE_PREFIX . "panels"; + const TABLE_APIKEYS = self::TABLE_PREFIX . "apikeys"; + const TABLE_DYNDNS = self::TABLE_PREFIX . "dyndns"; public function __construct(private readonly ConfigController $configController) { - $dbHost = $this->configController->getConfig(configKey: 'dbHost'); - $dbPort = $this->configController->getConfig(configKey: 'dbPort'); + $dbHost = $this->configController->getConfig(configKey: 'dbHost'); + $dbPort = $this->configController->getConfig(configKey: 'dbPort'); $dbDatabase = $this->configController->getConfig(configKey: 'dbDatabase'); - $dbUser = $this->configController->getConfig(configKey: 'dbUser'); + $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 + ); if (!$this->configController->getConfig(configKey: 'test')) { // TODO create config => encryption key try { - $this->dbConnection = new PDO( - dsn: "mysql:host=$dbHost;port=$dbPort;charset=utf8mb4;dbname=$dbDatabase", - username: $dbUser, - password: $dbPassword - ); $sql = "SHOW TABLES"; + $statement = $this->dbConnection->prepare(query: $sql); $statement->execute(); $result = $statement->fetch(); @@ -47,7 +48,7 @@ class DatabaseConnection // ALTER TABLE `domains` ADD `panel_id` INT NULL AFTER `id`; echo 'Error: Cannot find tables.' . PHP_EOL; if (confirm(message: 'Should I try to create them?')) { - $sql = " + $sql = " CREATE TABLE `apikeys` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, @@ -58,7 +59,7 @@ class DatabaseConnection $statement = $this->dbConnection->prepare(query: $sql); $statement->execute(); - $sql = " + $sql = " CREATE TABLE `domains` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, @@ -68,7 +69,7 @@ class DatabaseConnection $statement = $this->dbConnection->prepare(query: $sql); $statement->execute(); - $sql = " + $sql = " CREATE TABLE `nameservers` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, @@ -80,7 +81,7 @@ class DatabaseConnection $statement = $this->dbConnection->prepare(query: $sql); $statement->execute(); - $sql = " + $sql = " CREATE TABLE `panels` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, @@ -133,7 +134,7 @@ class DatabaseConnection */ function generatePassword(int $length = 8): string { - $chars = '23456789bcdfhkmnprstvzBCDFHJKLMNPRSTVZ'; + $chars = '23456789bcdfhkmnprstvzBCDFHJKLMNPRSTVZ'; $shuffled = str_shuffle(string: $chars); return mb_substr(string: $shuffled, start: 0, length: $length); }