blob: dc25e8be7c0588ba5e931d3c23229c52a6561c16 (
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
|
<?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->getHost() .
(($cred->getPort() !== '') ? ";port=" . $cred->getPort() : '') .
";dbname=" . $cred->getDBName(),
$cred->getLogin(),
$cred->getPassword()
);
// 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))));
}
}
}
|