From bd886f4a0f3f996295b0beb07a5b14b3b1b089f9 Mon Sep 17 00:00:00 2001
From: filippo.bertilotti <filippobertilotti@gmail.com>
Date: Thu, 23 May 2024 12:02:53 +0200
Subject: [PATCH] inizializzazione metodo update che permette di processare dati messi nella edit page (parte 135)

---
 src/App/Database.php |   19 +++++++++++++------
 1 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/src/App/Database.php b/src/App/Database.php
index e96b35b..c39c393 100644
--- a/src/App/Database.php
+++ b/src/App/Database.php
@@ -5,15 +5,22 @@
 use PDO;
 
 class Database {
-
+    private ?PDO $pdo = null;
     public function __construct(private string $host,
                                 private string $name,
                                 private string $user,
-                                private string $password) { }
+                                private string $password) {
+
+    }
     public function getConnection(): PDO {
-        $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
-        ]);
+        if ($this->pdo === null) {
+            $dns = "mysql:host={$this->host};dbname={$this->name};charset=utf8;port=3306";
+            $this->pdo = new PDO($dns, $this->user, $this->password, [
+                PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
+            ]);
+        }
+        
+        return $this->pdo;
+        
     }
 }
\ No newline at end of file

--
Gitblit v1.8.0