Total Complexity | 6 |
Total Lines | 32 |
Duplicated Lines | 0 % |
Coverage | 92.86% |
Changes | 0 |
1 | <?php |
||
16 | class ActiveRecord |
||
17 | { |
||
18 | private static $dbh; |
||
19 | private static $sth; |
||
20 | |||
21 | 30 | public static function conn(string $dsn, string $user, string $pass) |
|
22 | { |
||
23 | 30 | ActiveRecord::$dbh = new PDO($dsn, $user, $pass); |
|
24 | 30 | ActiveRecord::$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
|
25 | 30 | } |
|
26 | |||
27 | 30 | private static function getConn(): PDO |
|
28 | { |
||
29 | 30 | return ActiveRecord::$dbh; |
|
30 | } |
||
31 | |||
32 | 30 | private static function prepare(string $query): PDOStatement |
|
35 | } |
||
36 | |||
37 | 30 | protected static function execute(string $query, array $parameters = []): ?PDOStatement |
|
38 | { |
||
39 | 30 | if (ActiveRecord::prepare($query)->execute($parameters)) { |
|
40 | 30 | return ActiveRecord::$sth; |
|
41 | } |
||
42 | return null; |
||
43 | } |
||
44 | |||
45 | 30 | public static function exec(string $sql): int |
|
48 | } |
||
49 | } |
||
50 |