-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDB.php
More file actions
31 lines (23 loc) · 646 Bytes
/
DB.php
File metadata and controls
31 lines (23 loc) · 646 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
declare(strict_types=1);
namespace DIH;
class DB {
private $conn = null;
private static $instance = null;
public function __construct(string $dsn, string $user, string $password) { //{{{
if (!$this->conn = new \PDO($dsn, $user, $password)) {
throw new \Exception('Problem connecting to database');
}
}
//}}}
// run query
public function query(string $sql) : array { //{{{
$stmt = $this->conn->prepare($sql);
if (!$stmt->execute()) {
throw new \Exception('Problem with running query');
}
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
}
//}}}
}
?>