Show sourcecode
The following files exists in this folder. Click to view.
api/
createroom.php
createtables.php
createuser.php
css/
dbconnection.php
game.php
index.php
login.php
logout.php
remove.php
rensa.php
results.php
waiting.php
createtables.php
63 lines UTF-8 Windows (CRLF)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
<?php
include('dbconnection.php');
/** @var PDO $dbconn */
try {
// Skapa en sql-sats som skapar alla tabeller
$sql = "CREATE TABLE IF NOT EXISTS fq_users (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(50) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS fq_rooms (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
room_code VARCHAR(7) NOT NULL UNIQUE,
created_by INT UNSIGNED NOT NULL,
status ENUM('waiting', 'playing', 'finished') DEFAULT 'waiting',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (created_by) REFERENCES fq_users(id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS fq_room_players (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
room_id INT UNSIGNED NOT NULL,
user_id INT UNSIGNED NOT NULL,
joined_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
UNIQUE KEY unique_room_user (room_id, user_id),
FOREIGN KEY (room_id) REFERENCES fq_rooms(id) ON DELETE CASCADE,
FOREIGN KEY (user_id) REFERENCES fq_users(id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS fq_game_sessions (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
room_id INT UNSIGNED NOT NULL UNIQUE,
current_round INT UNSIGNED DEFAULT 1,
current_movie_title VARCHAR(255) DEFAULT NULL,
current_backdrop_path VARCHAR(255) DEFAULT NULL,
status ENUM('active', 'round_over', 'finished') DEFAULT 'active',
started_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
round_started_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (room_id) REFERENCES fq_rooms(id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS fq_scores (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
session_id INT UNSIGNED NOT NULL,
user_id INT UNSIGNED NOT NULL,
points INT UNSIGNED DEFAULT 0,
UNIQUE KEY unique_session_user (session_id, user_id),
FOREIGN KEY (session_id) REFERENCES fq_game_sessions(id) ON DELETE CASCADE,
FOREIGN KEY (user_id) REFERENCES fq_users(id) ON DELETE CASCADE
)";
// Kör sql-satsen
$dbconn->exec($sql);
echo "Tables created successfully";
} catch (PDOException $e) {
// Om det blir fel, skriv ut felmeddelandet
echo $sql . "<br>" . $e->getMessage();
}
$dbconn = null;