corso https://vola.udemy.com/course/php-mvc-from-scratch/learn/lecture/40931984#overview
filippo.bertilotti
2024-05-15 8cb4bd47128f836255687a635f76c0e6fd3dc643
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     echo "Created Database";
15
16     }
28ab07 17     public function getConnection(): PDO {
7739ea 18         $dns = "mysql:host={$this->host};dbname={$this->name};charset=utf8;port=3306";
F 19         return new PDO($dns, $this->user, $this->password, [
28ab07 20             PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
F 21         ]);
22     }
23 }