progetto fatto precedentemente adattato al framework creato con il corso
filippo.bertilotti
2024-06-06 f9a80024b0d5bfd2367808980a091ef29ce63c0f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php
 
namespace App;
 
use PDO;
 
class Database {
    private ?PDO $pdo = null;
    public function __construct(private string $host,
                                private string $name,
                                private string $user,
                                private string $password) {
 
    }
    public function getConnection(): PDO {
        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;
        
    }
}