-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabase.php
More file actions
27 lines (24 loc) · 885 Bytes
/
Database.php
File metadata and controls
27 lines (24 loc) · 885 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
<?php
//Contributions
//This part done by David
class Database {
private $pdo;
public function __construct(array $config) {
$dsn = "pgsql:host={$config['host']};port={$config['port']};dbname={$config['dbname']}";
$options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];
$this->pdo = new PDO($dsn, $config['user'], $config['password'], $options); //PDO with secure defaults
}
public function prepare(string $sql): PDOStatement {
return $this->pdo->prepare($sql); //wrapper to keep SQL safe
}
public function query(string $sql): PDOStatement {
$stmt = $this->prepare($sql);
$stmt->execute();
return $stmt; //for SELECTs
}
}
?>