blob: 42cba28a7ec8b88a6328d537774938ca3414839b (
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 $e) {
// we destroy $cred as quickly as possible
$cred = null;
die(json_encode(array("Result-Type" => "Error", "Content" => array($e->getMessage()))));
}
return $this;
}
}
|