summaryrefslogtreecommitdiff
path: root/classes/db.php
diff options
context:
space:
mode:
Diffstat (limited to 'classes/db.php')
-rwxr-xr-xclasses/db.php29
1 files changed, 20 insertions, 9 deletions
diff --git a/classes/db.php b/classes/db.php
index a760d4402..a30ffad31 100755
--- a/classes/db.php
+++ b/classes/db.php
@@ -1,27 +1,38 @@
<?php
class Db
{
- /* @var Db $instance */
+ /** @var Db $instance */
private static $instance;
private $link;
- /* @var PDO $pdo */
+ /** @var PDO $pdo */
private $pdo;
+ function __construct() {
+ ORM::configure(self::get_dsn());
+ ORM::configure('username', Config::get(Config::DB_USER));
+ ORM::configure('password', Config::get(Config::DB_PASS));
+ ORM::configure('return_result_sets', true);
+ }
+
private function __clone() {
//
}
- // this really shouldn't be used unless a separate PDO connection is needed
- // normal usage is Db::pdo()->prepare(...) etc
- public function pdo_connect() {
-
+ public static function get_dsn() {
$db_port = Config::get(Config::DB_PORT) ? ';port=' . Config::get(Config::DB_PORT) : '';
$db_host = Config::get(Config::DB_HOST) ? ';host=' . Config::get(Config::DB_HOST) : '';
+ return Config::get(Config::DB_TYPE) . ':dbname=' . Config::get(Config::DB_NAME) . $db_host . $db_port;
+ }
+
+ // this really shouldn't be used unless a separate PDO connection is needed
+ // normal usage is Db::pdo()->prepare(...) etc
+ public function pdo_connect() : PDO {
+
try {
- $pdo = new PDO(Config::get(Config::DB_TYPE) . ':dbname=' . Config::get(Config::DB_NAME) . $db_host . $db_port,
+ $pdo = new PDO(self::get_dsn(),
Config::get(Config::DB_USER),
Config::get(Config::DB_PASS));
} catch (Exception $e) {
@@ -49,7 +60,7 @@ class Db
return $pdo;
}
- public static function instance() {
+ public static function instance() : Db {
if (self::$instance == null)
self::$instance = new self();
@@ -60,7 +71,7 @@ class Db
if (self::$instance == null)
self::$instance = new self();
- if (!self::$instance->pdo) {
+ if (empty(self::$instance->pdo)) {
self::$instance->pdo = self::$instance->pdo_connect();
}