diff options
Diffstat (limited to 'app')
| -rw-r--r-- | app/class/database.class.php | 32 | 
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;      }      /* | 
