-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabase.php
More file actions
35 lines (31 loc) · 836 Bytes
/
Copy pathDatabase.php
File metadata and controls
35 lines (31 loc) · 836 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
<?php
class Database
{
private $username;
private $password;
private $host;
private $database;
public function __construct()
{
$this->username = 'dbuser';
$this->password = 'dbpwd';
$this->host = 'db';
$this->database = 'dbname';
}
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());
}
}
}