diff options
| -rw-r--r-- | app/class/database.class.php | 51 | 
1 files changed, 51 insertions, 0 deletions
| diff --git a/app/class/database.class.php b/app/class/database.class.php index cdfdfce..3d94e16 100644 --- a/app/class/database.class.php +++ b/app/class/database.class.php @@ -115,6 +115,57 @@ abstract class database          return true;      } + +    /* +     * Test and set new database configuration parameters. +     * If the given params fail, error's are set and this +     * function returns false.  On success, parameters are +     * written to 'dbconfig.php' and true is returned. +     */ +    public static function setConfig(string $engine, string $host, +        string $uname, string $passwd, string $name) : bool +    { +        global $_SCROTT; + +        /* test configuration */ +        $_SCROTT['conf'] = "conf"; +        $_SCROTT['dbEngine'] = $engine; +        $_SCROTT['dbHost'] = $host; +        $_SCROTT['dbUname'] = $uname; +        $_SCROTT['dbPasswd'] = $passwd; +        $_SCROTT['dbName'] = $name; + +        try +        { +            $db = self::getInstance(); +        } +        catch (Exception $e) +        { +            logError(ERROR, $e->getMessage()); +            return false; +        } + +        /* write file */ +        $f = fopen(DATABASE_CONFIG_FILE, "w"); + +        if (!$f) +        { +            logError(ERROR, "Can not create configuration file"); +            return false; +        } + +        fwrite($f, "<?php\n"); +        fwrite($f, "\$_SCROTT['conf'] = 'conf';\n"); +        fwrite($f, "\$_SCROTT['dbEngine'] = '" . $engine . "';\n"); +        fwrite($f, "\$_SCROTT['dbHost'] = '" . $host . "';\n"); +        fwrite($f, "\$_SCROTT['dbUname'] = '" . $uname . "';\n"); +        fwrite($f, "\$_SCROTT['dbPasswd'] = '" . $passwd . "';\n"); +        fwrite($f, "\$_SCROTT['dbName'] = '" . $name . "';\n"); +        fwrite($f, "?>\n"); + +        fclose($f); +        return true; +    }  }  ?> | 
