summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMalf Furious <m@lfurio.us>2015-12-17 01:36:09 -0500
committerMalf Furious <m@lfurio.us>2015-12-17 01:36:09 -0500
commit886bc202b8debe29f0c3e70b027ad3202e78c263 (patch)
tree2c393c3655ba0373e622106bb89055265d8a0c90
parentbdc8790368e2f8b247c8492507d4083ddfbd61c1 (diff)
downloadscrott-886bc202b8debe29f0c3e70b027ad3202e78c263.tar.gz
scrott-886bc202b8debe29f0c3e70b027ad3202e78c263.zip
+ Added function to framework class for getting (or creating) the app's singleton db connection object. If no connection is established, logic uses system-level configuration to decide how to connect before returning
-rw-r--r--app/class/framework.class.php32
1 files changed, 32 insertions, 0 deletions
diff --git a/app/class/framework.class.php b/app/class/framework.class.php
index 7244220..eea6c25 100644
--- a/app/class/framework.class.php
+++ b/app/class/framework.class.php
@@ -4,11 +4,15 @@
is_file("scrott.conf.php") &&
require_once "scrott.conf.php";
+require_once "class/mysql.class.php";
+
/*
* Global functions / operations and access to contextual or session-based information
*/
abstract class Framework
{
+ static $dbobj = null;
+
/*
* Check for the existence of Scrott's system-level config
*/
@@ -42,6 +46,34 @@ abstract class Framework
header("Location: " . $url);
exit;
}
+
+ /*
+ * Get or create the app's database connection object (this is a singleton object and dependent on system-level config)
+ */
+ function getDbConnection()
+ {
+ global $_SCROTT;
+
+ if (self::$dbobj != null)
+ return self::$dbobj;
+
+ switch ($_SCROTT['dbEngine'])
+ {
+ case "mysql":
+ $host = $_SCROTT['dbAddress'];
+ $username = $_SCROTT['dbUser'];
+ $password = $_SCROTT['dbPass'];
+ $dbName = $_SCROTT['dbName'];
+ self::$dbobj = new Mysql($host, $username, $password, $dbName);
+ break;
+
+ default:
+ throw new Exception("Problem with Scrott Configuration. Invalid database engine specified.");
+ break;
+ }
+
+ return self::$dbobj;
+ }
}
?>