progetto fatto precedentemente adattato al framework creato con il corso
filippo.bertilotti
2024-06-11 a13080a7484e40a5fb87fa2fe1980856eb60f252
commit | author | age
15e03a 1 <?php
F 2
3 namespace App;
4
5 use PDO;
6
7 class Database {
8     private ?PDO $pdo = null;
9     public function __construct(private string $host,
10                                 private string $name,
11                                 private string $user,
12                                 private string $password) {
13
14     }
15     public function getConnection(): PDO {
16         if ($this->pdo === null) {
17             $dns = "mysql:host={$this->host};dbname={$this->name};charset=utf8;port=3306";
18             $this->pdo = new PDO($dns, $this->user, $this->password, [
19                 PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
20             ]);
21         }
22         
23         return $this->pdo;
24         
25     }
26 }