113 lines
4.8 KiB
PHP
113 lines
4.8 KiB
PHP
<?php
|
|
// This script sets up the database tables and seeds them with initial data.
|
|
|
|
require_once __DIR__ . '/config.php';
|
|
|
|
function setup_database() {
|
|
try {
|
|
$pdo = db();
|
|
|
|
// Create sessions table if it doesn't exist
|
|
$pdo->exec("CREATE TABLE IF NOT EXISTS sessions (
|
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
time VARCHAR(255) NOT NULL,
|
|
title VARCHAR(255) NOT NULL,
|
|
speaker VARCHAR(255) NOT NULL,
|
|
description TEXT
|
|
)");
|
|
|
|
// Create speakers table if it doesn't exist
|
|
$pdo->exec("CREATE TABLE IF NOT EXISTS speakers (
|
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
name VARCHAR(255) NOT NULL,
|
|
bio TEXT,
|
|
photo_url VARCHAR(255),
|
|
slug VARCHAR(255) UNIQUE NOT NULL
|
|
)");
|
|
|
|
// Check if sessions table is empty
|
|
$stmt = $pdo->query("SELECT COUNT(*) FROM sessions");
|
|
$count = $stmt->fetchColumn();
|
|
|
|
if ($count == 0) {
|
|
// Schedule data to insert
|
|
$seed_schedule = [
|
|
[
|
|
'time' => '9:00 AM - 10:00 AM',
|
|
'title' => 'Opening Keynote',
|
|
'speaker' => 'Jane Doe',
|
|
'description' => 'A look at the future of web development and the latest trends in the industry.'
|
|
],
|
|
[
|
|
'time' => '10:15 AM - 11:15 AM',
|
|
'title' => 'The Power of Modern PHP',
|
|
'speaker' => 'John Smith',
|
|
'description' => 'Exploring the new features of PHP 8 and how to write more efficient and readable code.'
|
|
],
|
|
[
|
|
'time' => '11:30 AM - 12:30 PM',
|
|
'title' => 'Frontend Magic with Vanilla JS',
|
|
'speaker' => 'Emily White',
|
|
'description' => 'Building interactive and dynamic user interfaces without the need for heavy frameworks.'
|
|
],
|
|
[
|
|
'time' => '1:30 PM - 2:30 PM',
|
|
'title' => 'Securing Your Web Applications',
|
|
'speaker' => 'Michael Brown',
|
|
'description' => 'Best practices for protecting your applications from common vulnerabilities.'
|
|
]
|
|
];
|
|
|
|
$stmt = $pdo->prepare("INSERT INTO sessions (time, title, speaker, description) VALUES (:time, :title, :speaker, :description)");
|
|
foreach ($seed_schedule as $item) {
|
|
$stmt->execute($item);
|
|
}
|
|
}
|
|
|
|
// Check if speakers table is empty
|
|
$stmt = $pdo->query("SELECT COUNT(*) FROM speakers");
|
|
$count = $stmt->fetchColumn();
|
|
|
|
if ($count == 0) {
|
|
// Speaker data to insert
|
|
$seed_speakers = [
|
|
[
|
|
'name' => 'Jane Doe',
|
|
'bio' => 'Jane Doe is a renowned expert in web development with over 15 years of experience. She is a frequent speaker at international conferences and has authored several books on the subject.',
|
|
'photo_url' => 'https://i.pravatar.cc/150?u=jane_doe',
|
|
'slug' => 'jane-doe'
|
|
],
|
|
[
|
|
'name' => 'John Smith',
|
|
'bio' => 'John Smith is a core contributor to the PHP language and has been instrumental in its recent developments. He is passionate about open source and loves to share his knowledge with the community.',
|
|
'photo_url' => 'https://i.pravatar.cc/150?u=john_smith',
|
|
'slug' => 'john-smith'
|
|
],
|
|
[
|
|
'name' => 'Emily White',
|
|
'bio' => 'Emily White is a frontend developer who specializes in creating beautiful and performant user interfaces. She is a strong advocate for web standards and accessibility.',
|
|
'photo_url' => 'https://i.pravatar.cc/150?u=emily_white',
|
|
'slug' => 'emily-white'
|
|
],
|
|
[
|
|
'name' => 'Michael Brown',
|
|
'bio' => 'Michael Brown is a security researcher and ethical hacker. He has helped numerous companies secure their web applications and is a regular trainer at security bootcamps.',
|
|
'photo_url' => 'https://i.pravatar.cc/150?u=michael_brown',
|
|
'slug' => 'michael-brown'
|
|
]
|
|
];
|
|
|
|
$stmt = $pdo->prepare("INSERT INTO speakers (name, bio, photo_url, slug) VALUES (:name, :bio, :photo_url, :slug)");
|
|
foreach ($seed_speakers as $speaker) {
|
|
$stmt->execute($speaker);
|
|
}
|
|
}
|
|
|
|
} catch (PDOException $e) {
|
|
// In a real app, log this error and show a generic message
|
|
die('DB Setup Error: ' . $e->getMessage());
|
|
}
|
|
}
|
|
|
|
setup_database();
|