45 lines
1.4 KiB
PHP
45 lines
1.4 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../config.php';
|
|
|
|
try {
|
|
$pdo = db();
|
|
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
|
|
// Truncate the tables to start fresh
|
|
$pdo->exec("SET FOREIGN_KEY_CHECKS=0;");
|
|
$pdo->exec("TRUNCATE TABLE discussion_forums");
|
|
$pdo->exec("TRUNCATE TABLE discussion_threads");
|
|
$pdo->exec("TRUNCATE TABLE discussion_posts");
|
|
$pdo->exec("SET FOREIGN_KEY_CHECKS=1;");
|
|
|
|
// Find a course to associate with a forum
|
|
$stmt = $pdo->query("SELECT id FROM courses WHERE title LIKE '%PHP%' LIMIT 1");
|
|
$php_course = $stmt->fetch();
|
|
$php_course_id = $php_course ? $php_course['id'] : null;
|
|
|
|
$forums = [
|
|
[
|
|
'course_id' => null,
|
|
'title' => 'General Discussion',
|
|
'description' => 'A place to talk about anything and everything.'
|
|
],
|
|
[
|
|
'course_id' => $php_course_id,
|
|
'title' => 'PHP Course Q&A',
|
|
'description' => 'Ask questions and get help for the Introduction to PHP course.'
|
|
]
|
|
];
|
|
|
|
$stmt = $pdo->prepare("INSERT INTO discussion_forums (course_id, title, description) VALUES (:course_id, :title, :description)");
|
|
|
|
foreach ($forums as $forum) {
|
|
$stmt->execute($forum);
|
|
}
|
|
|
|
echo "Successfully seeded the discussion_forums table.\n";
|
|
|
|
} catch (PDOException $e) {
|
|
die("Seeding failed: " . $e->getMessage());
|
|
}
|
|
|