-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabase.php
More file actions
executable file
·37 lines (32 loc) · 873 Bytes
/
Database.php
File metadata and controls
executable file
·37 lines (32 loc) · 873 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
32
33
34
35
36
37
<?php
require_once "config.php";
class Database {
private $username;
private $password;
private $host;
private $database;
public function __construct()
{
$this->username = USERNAME;
$this->password = PASSWORD;
$this->host = HOST;
$this->database = DATABASE;
}
public function connect()
{
try {
$conn = new PDO(
"pgsql:host=$this->host;port=5432;dbname=$this->database",
$this->username,
$this->password,
["sslmode" => "prefer"]
);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $conn;
}
catch(PDOException $e) {
die("Connection failed: " . $e->getMessage());
}
}
}