setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Create users table $pdo->exec(" CREATE TABLE IF NOT EXISTS `users` ( `id` INT AUTO_INCREMENT PRIMARY KEY, `username` VARCHAR(255) NOT NULL UNIQUE, `password` VARCHAR(255) NOT NULL, `role` VARCHAR(50) NOT NULL, `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; "); // Create clubs table $pdo->exec(" CREATE TABLE IF NOT EXISTS `clubs` ( `id` INT AUTO_INCREMENT PRIMARY KEY, `name` VARCHAR(255) NOT NULL, `address` VARCHAR(255) NOT NULL, `number` VARCHAR(50), `neighborhood` VARCHAR(100), `city` VARCHAR(100) NOT NULL, `description` TEXT, `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; "); // Create tournaments table $pdo->exec(" CREATE TABLE IF NOT EXISTS `tournaments` ( `id` INT AUTO_INCREMENT PRIMARY KEY, `name` VARCHAR(255) NOT NULL, `description` TEXT, `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; "); // Check if superadmin exists $stmt = $pdo->prepare("SELECT id FROM users WHERE username = 'superadmin'"); $stmt->execute(); if ($stmt->fetch()) { echo "Superadmin user already exists.
"; } else { // Insert default superadmin user $username = 'superadmin'; $password = 'superadmin'; // Default password, you should change this $hashed_password = password_hash($password, PASSWORD_DEFAULT); $role = 'superadmin'; $stmt = $pdo->prepare("INSERT INTO users (username, password, role) VALUES (:username, :password, :role)"); $stmt->bindParam(':username', $username); $stmt->bindParam(':password', $hashed_password); $stmt->bindParam(':role', $role); $stmt->execute(); echo "Superadmin user created successfully with username 'superadmin' and password 'superadmin'.
"; } echo "Database setup completed successfully!
"; echo "You can now delete this file (db/setup.php) for security reasons."; } catch (PDOException $e) { die("Database setup failed: " . $e->getMessage()); }