exec("ALTER TABLE scores ENGINE=InnoDB"); echo "Table 'scores' engine converted to InnoDB.
"; // Check if player_id column exists $stmt = $pdo->query("SHOW COLUMNS FROM scores LIKE 'player_id'"); if ($stmt->rowCount() == 0) { // Add player_id column $pdo->exec("ALTER TABLE scores ADD COLUMN player_id INT NOT NULL AFTER course_id"); // Add foreign key constraint $pdo->exec("ALTER TABLE scores ADD FOREIGN KEY (player_id) REFERENCES players(id)"); echo "Column 'player_id' added to 'scores' table and foreign key created.
"; } else { echo "Column 'player_id' already exists in 'scores' table.
"; } // Check if team_id column exists $stmt = $pdo->query("SHOW COLUMNS FROM scores LIKE 'team_id'"); if ($stmt->rowCount() == 0) { // Add team_id column $pdo->exec("ALTER TABLE scores ADD COLUMN team_id INT NOT NULL AFTER player_id"); // Add foreign key constraint $pdo->exec("ALTER TABLE scores ADD FOREIGN KEY (team_id) REFERENCES teams(id)"); echo "Column 'team_id' added to 'scores' table and foreign key created.
"; } else { echo "Column 'team_id' already exists in 'scores' table.
"; } // Safely remove player_name and team_name if they exist $stmt = $pdo->query("SHOW COLUMNS FROM scores LIKE 'player_name'"); if ($stmt->rowCount() > 0) { $pdo->exec("ALTER TABLE scores DROP COLUMN player_name"); echo "Column 'player_name' removed from 'scores' table.
"; } $stmt = $pdo->query("SHOW COLUMNS FROM scores LIKE 'team_name'"); if ($stmt->rowCount() > 0) { $pdo->exec("ALTER TABLE scores DROP COLUMN team_name"); echo "Column 'team_name' removed from 'scores' table.
"; } } catch (PDOException $e) { die("DB ERROR: " . $e->getMessage()); } ?>