blob: 4afa33071a1a2574d001dab8631d517b6e25ea95 (
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
42
|
<?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
// breaks side-effect rule
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;
throw $err; // throw for Controller to catch
}
return $this;
}
}
|