";
} else {
echo "Error creating database: " . mysqli_error($conn) . "
";
}
// 2. Connect to the specific Database 'sudoku'
mysqli_select_db($conn, $db);
// 3. Create 'users' table
$sqlUsers = "
CREATE TABLE IF NOT EXISTS users (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(50) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci";
if (mysqli_query($conn, $sqlUsers)) {
echo "Table 'users' successfully checked/created.
";
// Seed default users if table is empty
$checkResult = mysqli_query($conn, "SELECT count(*) as total FROM users");
$row = mysqli_fetch_assoc($checkResult);
if ($row['total'] == 0) {
$password = password_hash('123456', PASSWORD_DEFAULT); // Default password
// Using prepare statement for insertion to be safe, though not strictly necessary for hardcoded
$sqlInsert = "INSERT INTO users (username, password) VALUES ('admin', '$password'), ('player1', '$password')";
if (mysqli_query($conn, $sqlInsert)) {
echo "Default users (admin, player1) created with password '123456'.
";
}
}
} else {
echo "Error Creating 'users': " . mysqli_error($conn) . "
";
}
// 4. Create 'leaderboard_sudoku' table
$sqlLeaderboard = "
CREATE TABLE IF NOT EXISTS leaderboard_sudoku (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(50),
difficulty VARCHAR(10),
time_seconds INT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)";
if (mysqli_query($conn, $sqlLeaderboard)) {
echo "Table 'leaderboard_sudoku' successfully checked/created.
";
} else {
echo "Error Creating 'leaderboard_sudoku': " . mysqli_error($conn) . "
";
}
echo "