diff options
author | Malf Furious <m@lfurio.us> | 2015-12-17 01:36:09 -0500 |
---|---|---|
committer | Malf Furious <m@lfurio.us> | 2015-12-17 01:36:09 -0500 |
commit | 886bc202b8debe29f0c3e70b027ad3202e78c263 (patch) | |
tree | 2c393c3655ba0373e622106bb89055265d8a0c90 /app | |
parent | bdc8790368e2f8b247c8492507d4083ddfbd61c1 (diff) | |
download | scrott-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
Diffstat (limited to 'app')
-rw-r--r-- | app/class/framework.class.php | 32 |
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; + } } ?> |