From 4dbbdf331906f5e6fba5ae674ea88be7dd633dc1 Mon Sep 17 00:00:00 2001 From: filippo.bertilotti <filippobertilotti@gmail.com> Date: Thu, 23 May 2024 09:47:41 +0200 Subject: [PATCH] estrazione del codice in comune nella classe Model (parte 130) --- src/App/Database.php | 11 +++++++++-- 1 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/App/Database.php b/src/App/Database.php index 3d9969d..a239bdb 100644 --- a/src/App/Database.php +++ b/src/App/Database.php @@ -5,9 +5,16 @@ use PDO; class Database { + + public function __construct(private string $host, + private string $name, + private string $user, + private string $password) { + + } public function getConnection(): PDO { - $dns = "mysql:host=localhost;dbname=product_db;charset=utf8;port=3306"; - return new PDO($dns, "product_db_user", "secret", [ + $dns = "mysql:host={$this->host};dbname={$this->name};charset=utf8;port=3306"; + return new PDO($dns, $this->user, $this->password, [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ]); } -- Gitblit v1.8.0