corso https://vola.udemy.com/course/php-mvc-from-scratch/learn/lecture/40931984#overview
filippo.bertilotti
2024-05-23 4dbbdf331906f5e6fba5ae674ea88be7dd633dc1
commit | author | age
28ab07 1 <?php
F 2
3 namespace App;
4
5 use PDO;
6
7 class Database {
7739ea 8
F 9     public function __construct(private string $host,
10                                 private string $name,
11                                 private string $user,
75438d 12                                 private string $password) {
F 13
14     }
28ab07 15     public function getConnection(): PDO {
7739ea 16         $dns = "mysql:host={$this->host};dbname={$this->name};charset=utf8;port=3306";
F 17         return new PDO($dns, $this->user, $this->password, [
28ab07 18             PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
F 19         ]);
20     }
21 }