-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabase.php
More file actions
44 lines (37 loc) · 1.02 KB
/
Copy pathDatabase.php
File metadata and controls
44 lines (37 loc) · 1.02 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
/**
* Database Class
*
* Contains connection information to query PostgresSQL.
*/
class Database {
private $dbConnector;
/**
* Constructor
*
* Connects to PostgresSQL
*/
public function __construct() {
$host = Config::$db["host"];
$user = Config::$db["user"];
$database = Config::$db["database"];
$password = Config::$db["pass"];
$port = Config::$db["port"];
$this->dbConnector = pg_connect("host=$host port=$port dbname=$database user=$user password=$password");
}
/**
* Query
*
* Makes a query to posgres and returns an array of the results.
* The query must include placeholders for each of the additional
* parameters provided.
*/
public function query($query, ...$params) {
$res = pg_query_params($this->dbConnector, $query, $params);
if ($res === false) {
echo pg_last_error($this->dbConnector);
return false;
}
return pg_fetch_all($res);
}
}