blob: 48cf4fbed73c47a22c6e22156ce2456f5eba3616 (
plain) (
blame)
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
|
<?php
declare(strict_types=1);
namespace AugustOffensive\Model;
/**
* Model connection class for connecting to database via PDO.
*/
class Connection
{
/** @var \PDO $_conn PDO connection to database. */
private $conn;
/**
* Initiates connection to PostGreSQL database.
*
* @return Connection
*/
public function __construct ()
{
// Establish connection to db
include 'creds.php';
try {
$conn = new \PDO(
"pgsql: host=" . $cred->host .
(($cred->port !== '') ? ";port=" . $cred->port : '') .
";dbname=" . $cred->dbName,
$cred->login,
$cred->password
);
// we destroy $cred as quickly as possible
$cred = null;
} catch (\PDOException $err) {
// we destroy $cred as quickly as possible
$cred = null;
die(json_encode(array("Result-Type" => "ERROR", "Content" => array($err->getMessage()))));
}
return $this;
}
}
|