-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.php
More file actions
45 lines (40 loc) · 1.3 KB
/
Copy pathsetup.php
File metadata and controls
45 lines (40 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
// setup.php
error_reporting(E_ALL);
ini_set("display_errors", 1);
require __DIR__ . "/Config.php";
require __DIR__ . "/Database.php";
try {
$db = new Database();
$db->query("DROP TABLE IF EXISTS hw6_user_words, hw6_words, hw6_users CASCADE");
// Table: hw6_users
// Stores user credentials and statistics
$db->query("CREATE TABLE hw6_users (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL,
email TEXT UNIQUE NOT NULL,
password TEXT NOT NULL,
total_games INT DEFAULT 0,
games_won INT DEFAULT 0,
highest_score INT DEFAULT 0,
total_score BIGINT DEFAULT 0
)");
// Table: hw6_words
// Stores all available 7-letter target words
$db->query("CREATE TABLE hw6_words (
id SERIAL PRIMARY KEY,
word TEXT UNIQUE NOT NULL
)");
// Table: hw6_user_words
// Link table between users and words they’ve played
$db->query("CREATE TABLE hw6_user_words (
user_id INT REFERENCES hw6_users(id), -- FK to hw6_users.id
word_id INT REFERENCES hw6_words(id), -- FK to hw6_words.id
won BOOLEAN, -- Whether the user won the game (guessed full word)
score INT, -- Score earned in that game
PRIMARY KEY (user_id, word_id) -- Composite key to ensure unique pairing
)");
echo "Database tables created successfully!";
} catch (Exception $e) {
die("Error: " . $e->getMessage());
}