summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorMalf Furious <m@lfurio.us>2017-02-13 04:15:20 -0500
committerMalf Furious <m@lfurio.us>2017-02-13 04:15:20 -0500
commit30fc005d7cea626184ee57f3dea88881ad6cf6fa (patch)
tree1137b63d7f39be4ea708874d2a9493145e81c569 /app
parent912b28d44b340f9c418f3714d38df40e06f6f6da (diff)
downloadscrott-30fc005d7cea626184ee57f3dea88881ad6cf6fa.tar.gz
scrott-30fc005d7cea626184ee57f3dea88881ad6cf6fa.zip
Implement function database::getInstance()
Diffstat (limited to 'app')
-rw-r--r--app/class/database.class.php32
1 files changed, 30 insertions, 2 deletions
diff --git a/app/class/database.class.php b/app/class/database.class.php
index c0f13d7..74587f5 100644
--- a/app/class/database.class.php
+++ b/app/class/database.class.php
@@ -16,6 +16,9 @@
define("DATABASE_CONFIG_FILE", "dbconfig.php");
is_file(DATABASE_CONFIG_FILE) && require_once DATABASE_CONFIG_FILE;
+require_once "class/globals.php";
+require_once "class/mysql.class.php";
+
/*
* This class provides a common interface to various database drivers.
* Scrott provides facilities for interacting with any DBMS that we can
@@ -39,11 +42,36 @@ abstract class database
/*
* Return the database instance object, creating it if this is the
* first call to this function. This function will need maintained
- * as new DBMSs are supported.
+ * as new DBMSs are supported. This function will throw if the
+ * database is not configured.
*/
private static function getInstance() : database
{
- // TODO
+ global $_SCROTT;
+
+ if (self::$instance)
+ return self::$instance;
+
+ if (!isset($_SCROTT['conf']))
+ throw new Exception("Scrott database configuration is missing.");
+
+ switch ($_SCROTT['dbEngine'])
+ {
+ case "mysql":
+ $host = $_SCROTT['dbHost'];
+ $uname = $_SCROTT['dbUname'];
+ $passwd = $_SCROTT['dbPasswd'];
+ $dbname = $_SCROTT['dbName'];
+ self::$instance = new mysql($host, $uname, $passwd, $dbname);
+ break;
+
+ default:
+ throw new Exception("Problem with Scrott database configuration. Invalid " .
+ "database engine specified.");
+ break;
+ }
+
+ return self::$instance;
}
/*