34010-vm/db/config.php
Flatlogic Bot 52b5af3fbe www
2025-09-19 13:01:23 +00:00

98 lines
3.2 KiB
PHP

<?php
// Generated by setup_mariadb_project.sh — edit as needed.
define('DB_HOST', '127.0.0.1');
define('DB_NAME', 'app_34010');
define('DB_USER', 'app_34010');
define('DB_PASS', 'e689e56d-6f73-4dc6-b30b-aac78bb04979');
function db() {
static $pdo;
if (!$pdo) {
$dsn = 'mysql:host=' . DB_HOST . ';dbname=' . DB_NAME . ';charset=utf8mb4';
$options = [
PDO::ATTR_ERRMODE => 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();