diff options
author | Malf Furious <m@lfurio.us> | 2017-07-06 23:41:17 -0400 |
---|---|---|
committer | Malf Furious <m@lfurio.us> | 2017-07-06 23:41:17 -0400 |
commit | be0b63cae463f814aa7eef879c0994b8e3ca16ba (patch) | |
tree | c7e9797caffc0f8e2e18462a8e324fbbab33fbd9 /app | |
parent | b84f346e6534195de6d7485276ed81406a222703 (diff) | |
download | scrott-be0b63cae463f814aa7eef879c0994b8e3ca16ba.tar.gz scrott-be0b63cae463f814aa7eef879c0994b8e3ca16ba.zip |
Add function database::setConfig()
Diffstat (limited to 'app')
-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; + } } ?> |