added a side note

This commit is contained in:
tracer 2022-10-23 12:32:53 +02:00
parent 9cacf9ced9
commit cbbfe45c1b
1 changed files with 15 additions and 7 deletions

View File

@ -1,27 +1,35 @@
<?php <?php
/*
* Copyright (c) 2022. Micha Espey <tracer@24unix.net>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace App\Service; namespace App\Service;
use PDO; use PDO;
/** /**
* * Take care of the PDO object.
*/ */
class DatabaseConnection class DatabaseConnection
{ {
private PDO $dbConnection; private PDO $dbConnection;
// Currently no prefixes are used, but could be easily added to config.json.
const TABLE_PREFIX = ''; const TABLE_PREFIX = '';
const TABLE_USERS = self::TABLE_PREFIX . "users"; const TABLE_USERS = self::TABLE_PREFIX . "users";
const TABLE_ADDRESSES = self::TABLE_PREFIX . "addresses"; const TABLE_ADDRESSES = self::TABLE_PREFIX . "addresses";
public function __construct(private readonly Config $configController) public function __construct(private readonly Config $config)
{ {
$dbHost = $this->configController->getConfig(configKey: 'dbHost'); $dbHost = $this->config->getConfig(configKey: 'dbHost');
$dbPort = $this->configController->getConfig(configKey: 'dbPort'); $dbPort = $this->config->getConfig(configKey: 'dbPort');
$dbDatabase = $this->configController->getConfig(configKey: 'dbDatabase'); $dbDatabase = $this->config->getConfig(configKey: 'dbDatabase');
$dbUser = $this->configController->getConfig(configKey: 'dbUser'); $dbUser = $this->config->getConfig(configKey: 'dbUser');
$dbPassword = $this->configController->getConfig(configKey: 'dbPassword'); $dbPassword = $this->config->getConfig(configKey: 'dbPassword');
$this->dbConnection = new PDO( $this->dbConnection = new PDO(
dsn: "mysql:host=$dbHost;port=$dbPort;charset=utf8mb4;dbname=$dbDatabase", dsn: "mysql:host=$dbHost;port=$dbPort;charset=utf8mb4;dbname=$dbDatabase",