commit | author | age
|
28ab07
|
1 |
<?php |
F |
2 |
|
|
3 |
namespace App; |
|
4 |
|
|
5 |
use PDO; |
|
6 |
|
|
7 |
class Database { |
6704d0
|
8 |
private ?PDO $pdo = null; |
7739ea
|
9 |
public function __construct(private string $host, |
F |
10 |
private string $name, |
|
11 |
private string $user, |
75438d
|
12 |
private string $password) { |
F |
13 |
|
|
14 |
} |
28ab07
|
15 |
public function getConnection(): PDO { |
6704d0
|
16 |
if ($this->pdo === null) { |
F |
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 |
|
28ab07
|
25 |
} |
F |
26 |
} |