exec($sql); echo "Table 'users' created successfully." . PHP_EOL; // Add a default admin user if one doesn't exist $stmt = $pdo->prepare("SELECT COUNT(*) FROM users WHERE email = :email"); $stmt->execute(['email' => 'admin@example.com']); if ($stmt->fetchColumn() == 0) { $username = 'admin'; $email = 'admin@example.com'; $password = 'password'; // In a real app, use a stronger password and handle this securely $password_hash = password_hash($password, PASSWORD_DEFAULT); $role = 'admin'; $insert_sql = " INSERT INTO users (username, email, password_hash, role) VALUES (:username, :email, :password_hash, :role); "; $insert_stmt = $pdo->prepare($insert_sql); $insert_stmt->execute([ ':username' => $username, ':email' => $email, ':password_hash' => $password_hash, ':role' => $role ]); echo "Default admin user created (admin@example.com / password)." . PHP_EOL; } } catch (PDOException $e) { die("DB ERROR: " . $e->getMessage()); }