corso https://vola.udemy.com/course/php-mvc-from-scratch/learn/lecture/40931984#overview
filippo.bertilotti
2024-05-14 2bddb6faf9aeddf40602187c57c421da8ded5c3e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php
 
namespace App;
 
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={$this->host};dbname={$this->name};charset=utf8;port=3306";
        return new PDO($dns, $this->user, $this->password, [
            PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
        ]);
    }
}