aboutsummaryrefslogtreecommitdiff
path: root/private/model/Connection.php
diff options
context:
space:
mode:
authorKevin J Hoerr <kjhoerr@protonmail.com>2017-06-24 13:42:16 -0400
committerKevin J Hoerr <kjhoerr@protonmail.com>2017-06-24 13:42:16 -0400
commit4a6523cd2da9ccc5a2b4a334e7a33a84f97f1e5b (patch)
tree4be0e5a8e22d5e5a5dc1e9cf5e218864a61d361e /private/model/Connection.php
parent92a7e43b7d4792cdb54eceefd3256324a8eca458 (diff)
downloadaugust-offensive-4a6523cd2da9ccc5a2b4a334e7a33a84f97f1e5b.tar.gz
august-offensive-4a6523cd2da9ccc5a2b4a334e7a33a84f97f1e5b.tar.bz2
august-offensive-4a6523cd2da9ccc5a2b4a334e7a33a84f97f1e5b.zip
Add creds.php file, attempt to connect to database
Diffstat (limited to 'private/model/Connection.php')
-rw-r--r--private/model/Connection.php23
1 files changed, 22 insertions, 1 deletions
diff --git a/private/model/Connection.php b/private/model/Connection.php
index 26632f7..31b58c3 100644
--- a/private/model/Connection.php
+++ b/private/model/Connection.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types = On);
+
namespace AugustOffensive\model;
/**
@@ -7,6 +9,8 @@ namespace AugustOffensive\model;
*/
class Connection
{
+ /** @var PDO $_conn PDO connection to database. */
+ private $_conn;
/**
* Initiates connection to PostGreSQL database.
*
@@ -14,6 +18,23 @@ class 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 as $e) {
+ // we destroy $cred as quickly as possible
+ $cred = null;
+ die(json_encode(array("Result-Type" => "Error", "Content" => array($e))));
+ }
}
}