diff --git a/db/_ddd_db.sqlite b/db/_ddd_db.sqlite deleted file mode 100644 index 6369f7c..0000000 Binary files a/db/_ddd_db.sqlite and /dev/null differ diff --git a/db/ddd_db.sql b/db/ddd_db.sql new file mode 100644 index 0000000..b5aef4c --- /dev/null +++ b/db/ddd_db.sql @@ -0,0 +1,14 @@ +-- Create the database +CREATE DATABASE IF NOT EXISTS ddd_db; + +-- Switch to the database +USE ddd_db; + +-- Create the scores table +CREATE TABLE IF NOT EXISTS scores ( + id INT AUTO_INCREMENT PRIMARY KEY, + Name VARCHAR(255) NOT NULL, + Score BIGINT NOT NULL, + Mode VARCHAR(50) NOT NULL, + Bosses TEXT +); diff --git a/db/ddd_db.sqlite b/db/ddd_db.sqlite index c8aa2ca..4092ab3 100644 Binary files a/db/ddd_db.sqlite and b/db/ddd_db.sqlite differ diff --git a/ddd_scores.php b/ddd_scores.php index 552ad46..d8bb339 100755 --- a/ddd_scores.php +++ b/ddd_scores.php @@ -1,45 +1,74 @@ connect_error) { + die("Connection failed: " . $mysqli->connect_error); + } else { + $db = $mysqli; + } } elseif ($database === 'sqlite') { - $db_path = 'db/ddd_db.sqlite'; - $db = new SQLite3($db_path); + $db_path = 'db/ddd_db.sqlite'; + if (file_exists($db_path)) { + try { + $db = new SQLite3($db_path); + } catch (Exception $e) { + die("Failed to open the SQLite database: " . $e->getMessage()); + } + } else { + die("Database file does not exist: " . $db_path); + } } else { - echo "Unsupported database type specified in config.cfg\n"; + die("Unsupported database type specified in config.cfg"); } } else { - echo "Database configuration not found in config.cfg\n"; + die("Database configuration not found in config.cfg"); } +// Get mode from request +$mode = $_REQUEST['mode'] ?? 'DX'; - -$mode = $_REQUEST['mode']; - +// Construct query based on mode if ($mode == "DX") { - echo ""; - $query = "SELECT * FROM ddd_db.scores WHERE ddd_db.scores.Mode = 'DX' ORDER BY ddd_db.scores.Score DESC LIMIT 100"; + echo ""; + $query = "SELECT * FROM scores WHERE Mode = 'DX' ORDER BY Score DESC LIMIT 100"; } elseif ($mode == "EX") { - echo ""; - $query = "SELECT * FROM ddd_db.scores WHERE ddd_db.scores.Mode = 'EX' ORDER BY ddd_db.scores.Score DESC LIMIT 100"; + echo ""; + $query = "SELECT * FROM scores WHERE Mode = 'EX' ORDER BY Score DESC LIMIT 100"; +} else { + die("Invalid mode specified"); } -$result = $db->query($query); +// Execute query and fetch results +$result = null; + +if ($db instanceof SQLite3) { + $result = $db->query($query); +} elseif ($db instanceof mysqli) { + $result = $db->query($query); +} if ($result) { - // output data of each row $counter = 1; + echo "