diff options
author | Malf Furious <m@lfurio.us> | 2018-01-24 23:41:23 -0500 |
---|---|---|
committer | Malf Furious <m@lfurio.us> | 2018-01-24 23:41:23 -0500 |
commit | b8351dc9d172b8b00479066dab56c97874ad501c (patch) | |
tree | 25f0cbcb772a88847b5a8d67bd880ddf2f8ca33a /app/class/database.class.php | |
parent | 306d3d2b7b8538a5c2d1c8fc26852e83214725d0 (diff) | |
parent | 75dd0e67ca684f779b712b313f188d23f903609f (diff) | |
download | scrott-b8351dc9d172b8b00479066dab56c97874ad501c.tar.gz scrott-b8351dc9d172b8b00479066dab56c97874ad501c.zip |
Merge branch 'feature/ui-basics' into dev
Diffstat (limited to 'app/class/database.class.php')
-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; + } } ?> |