46 lines
1.2 KiB
PHP
46 lines
1.2 KiB
PHP
|
<?php
|
||
|
// Path to the SQLite database file
|
||
|
$db_path = 'db/ddd_db.sqlite';
|
||
|
|
||
|
// Check if the 'db' directory exists, if not, create it
|
||
|
if (!is_dir('db')) {
|
||
|
if (!mkdir('db', 0777, true)) {
|
||
|
die('Failed to create directories...');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Check if the database file exists
|
||
|
if (!file_exists($db_path)) {
|
||
|
try {
|
||
|
// Create a new SQLite3 database file
|
||
|
$db = new SQLite3($db_path);
|
||
|
|
||
|
// Create the 'scores' table
|
||
|
$createTableQuery = "
|
||
|
CREATE TABLE IF NOT EXISTS scores (
|
||
|
ID INTEGER PRIMARY KEY AUTOINCREMENT,
|
||
|
Name TEXT NOT NULL,
|
||
|
Score INTEGER NOT NULL,
|
||
|
Mode TEXT NOT NULL,
|
||
|
Bosses TEXT NOT NULL
|
||
|
);
|
||
|
";
|
||
|
|
||
|
if ($db->exec($createTableQuery)) {
|
||
|
echo "Database and table created successfully.<br>";
|
||
|
} else {
|
||
|
echo "Error creating table: " . $db->lastErrorMsg() . "<br>";
|
||
|
}
|
||
|
|
||
|
// Close the database connection
|
||
|
$db->close();
|
||
|
} catch (Exception $e) {
|
||
|
echo 'Caught exception: ', $e->getMessage(), "<br>";
|
||
|
} catch (Error $e) {
|
||
|
echo 'Caught error: ', $e->getMessage(), "<br>";
|
||
|
}
|
||
|
} else {
|
||
|
echo "Database already exists.<br>";
|
||
|
}
|
||
|
?>
|