aboutsummaryrefslogtreecommitdiff
path: root/private/Model/Connection.php
diff options
context:
space:
mode:
Diffstat (limited to 'private/Model/Connection.php')
-rw-r--r--private/Model/Connection.php41
1 files changed, 41 insertions, 0 deletions
diff --git a/private/Model/Connection.php b/private/Model/Connection.php
new file mode 100644
index 0000000..48cf4fb
--- /dev/null
+++ b/private/Model/Connection.php
@@ -0,0 +1,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;
+ }
+}