diff options
-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; + } } ?> |