summaryrefslogtreecommitdiff
path: root/setup.php
diff options
context:
space:
mode:
authorlshprung <lshprung@yahoo.com>2022-04-16 21:44:52 -0700
committerlshprung <lshprung@yahoo.com>2022-04-16 21:44:52 -0700
commit5709215241fc99eada2efcc770bfb33e7ee72e53 (patch)
tree8266da30f2f6440c6796e3ce230231e0abee6f96 /setup.php
parentd698e6eb153c956de48fb6a06d91844accc0f895 (diff)
Added automatic table creation to setup.php
Diffstat (limited to 'setup.php')
-rw-r--r--setup.php64
1 files changed, 56 insertions, 8 deletions
diff --git a/setup.php b/setup.php
index 0108510..7ed1928 100644
--- a/setup.php
+++ b/setup.php
@@ -24,20 +24,68 @@ if($check == "y"){
$input["socket"] = readline("Enter socket [leave blank for default]: ");
fwrite_wrapper($handle, "<?php\n\n");
- fwrite_wrapper($handle, "\$db = mysqli_connect(\"" .
- $input["hostname"] . "\"" .
- ", \"" . $input["username"] . "\"" .
- ", \"" . $input["password"] . "\"" .
- ", \"" . $input["database"] . "\"" .
- (!$input["port"] ? "" : ", " . $input["port"]) .
- (!$input["socket"] ? "" : ", \"" . $input["socket"] . "\"") . ");\n"
+ fwrite_wrapper($handle, "\$hostname = '" . $input["hostname"] . "';\n");
+ fwrite_wrapper($handle, "\$username = '" . $input["username"] . "';\n");
+ fwrite_wrapper($handle, "\$password = '" . $input["password"] . "';\n");
+ fwrite_wrapper($handle, "\$database = '" . $input["database"] . "';\n");
+ if($input["port"]) fwrite_wrapper($handle, "\$port = " . $input["port"] . ";\n");
+ fwrite_wrapper($handle, "\$socket = '" . $input["socket"] . "';\n\n");
+
+ fwrite_wrapper($handle, "\$db = mysqli_connect(" .
+ "\"\$hostname\"" .
+ ", \"\$username\"" .
+ ", \"\$password\"" .
+ ", \"\$database\"" .
+ (!$input["port"] ? "" : ", \$port") .
+ (!$input["socket"] ? "" : ", \"\$socket\"") . ");\n"
);
- fwrite_wrapper($handle, "if(!\$db) die(\"Failed to connect to database: \" . mysqli_connect_error());\n\n");
+ fwrite_wrapper($handle, "if(!\$db) die(\"\nFailed to connect to database: \" . mysqli_connect_error()\n);\n\n");
fwrite_wrapper($handle, "?>");
echo "\nSuccessfully wrote \"$config_path\"\n";
}
+$check = readline("Automatically create tables? [Y/n] ");
+
+if($check != "n"){
+ print "\n";
+
+ print "Testing connection using credentials...";
+ include "backend/config.php";
+ print "\tSuccess!\n";
+
+ GLOBAL $database;
+ $tables = [
+ "Classes" => "CREATE TABLE IF NOT EXISTS Classes (
+ ID int(11) NOT NULL AUTO_INCREMENT,
+ Name varchar(255) DEFAULT NULL,
+ Code varchar(255) NOT NULL,
+ Location tinyint(1) DEFAULT NULL,
+ Link varchar(255) DEFAULT NULL,
+ Hidden tinyint(1) DEFAULT '0',
+ PRIMARY KEY (ID))",
+ "Assignments" => "CREATE TABLE IF NOT EXISTS Assignments (
+ ID int(11) NOT NULL AUTO_INCREMENT,
+ Class_ID int(11) NOT NULL,
+ Due_date date DEFAULT NULL,
+ Alt_due_date varchar(255) DEFAULT NULL,
+ Description varchar(1024) NOT NULL,
+ Color varchar(255) DEFAULT NULL,
+ Highlight varchar(255) DEFAULT NULL,
+ Done tinyint(1) DEFAULT NULL,
+ Link varchar(255) DEFAULT NULL,
+ Hidden tinyint(1) DEFAULT '0',
+ PRIMARY KEY (ID))"
+ ];
+
+ foreach(array_keys($tables) as $key){
+ print "Creating table \"$key\"...";
+ $q = $tables[$key];
+ if(mysqli_query($db, $q)) print "\tSuccess!\n";
+ else die("$q\nInsertion Failed: " . mysqli_error($db) . "\n");
+ }
+}
+
function fwrite_wrapper($file, $string){
GLOBAL $config_path;