PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_EMULATE_PREPARES => false, ]; try { $pdo = new PDO($dsn, DB_USER, DB_PASS, $options); } catch (PDOException $e) { // In a real app, you'd log this error and show a generic message // For this demo, we'll just die with the error. die('Database connection failed: ' . $e->getMessage()); } } return $pdo; } function seed_initial_data() { $pdo = db(); // 1. Create venues table $pdo->exec(" CREATE TABLE IF NOT EXISTS venues ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255) NOT NULL, capacity INT NOT NULL, features TEXT, image_url VARCHAR(255), is_booked BOOLEAN DEFAULT FALSE, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ) "); // 2. Check if venues table is empty $stmt = $pdo->query("SELECT COUNT(*) FROM venues"); if ($stmt->fetchColumn() == 0) { // 3. Insert sample data $venues = [ [ 'name' => 'The Grand Ballroom', 'capacity' => 500, 'features' => '["Full A/V setup", "On-site catering", "Valet parking"]', 'image_url' => 'https://picsum.photos/seed/venue-1/800/600', 'is_booked' => false ], [ 'name' => 'The Rustic Barn', 'capacity' => 150, 'features' => '["Scenic views", "Outdoor space", "Bridal suite"]', 'image_url' => 'https://picsum.photos/seed/venue-2/800/600', 'is_booked' => true ], [ 'name' => 'Cityscape Rooftop', 'capacity' => 100, 'features' => '["360° city views", "Modern decor", "Cocktail bar"]', 'image_url' => 'https://picsum.photos/seed/venue-3/800/600', 'is_booked' => false ], [ 'name' => 'The Garden Pavilion', 'capacity' => 250, 'features' => '["Lush gardens", "Glass walls", "Natural light"]', 'image_url' => 'https://picsum.photos/seed/venue-4/800/600', 'is_booked' => false ] ]; $stmt = $pdo->prepare( "INSERT INTO venues (name, capacity, features, image_url, is_booked) VALUES (?, ?, ?, ?, ?)" ); foreach ($venues as $venue) { $stmt->execute([ $venue['name'], $venue['capacity'], $venue['features'], $venue['image_url'], $venue['is_booked'] ]); } } } // Run the seeder seed_initial_data();