34607-vm/db/seeds/seed_courses.php
Flatlogic Bot 34236e9979 1.0.0
2025-10-03 03:24:30 +00:00

78 lines
2.6 KiB
PHP

<?php
require_once __DIR__ . '/../config.php';
try {
$pdo = db();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Temporarily disable foreign key checks to truncate the table
$pdo->exec("SET FOREIGN_KEY_CHECKS=0;");
$pdo->exec("TRUNCATE TABLE courses");
$pdo->exec("SET FOREIGN_KEY_CHECKS=1;");
$courses = [
[
'title' => 'Introduction to PHP',
'description' => 'Learn the fundamentals of PHP, the most popular server-side scripting language.',
'tier' => 'free',
'price' => null,
'type' => 'course',
'instructor_id' => null // No instructor assigned yet
],
[
'title' => 'Advanced MySQL',
'description' => 'Master advanced MySQL concepts like indexing, transactions, and stored procedures.',
'tier' => 'premium',
'price' => '99.99',
'type' => 'course',
'instructor_id' => null
],
[
'title' => 'JavaScript for Beginners',
'description' => 'Get started with JavaScript, the language of the web.',
'tier' => 'free',
'price' => null,
'type' => 'course',
'instructor_id' => null
],
[
'title' => 'Quick CSS Flexbox',
'description' => 'A 25-minute dive into the essentials of CSS Flexbox for modern layouts.',
'tier' => 'free',
'price' => null,
'type' => 'micro-lesson',
'instructor_id' => null
],
[
'title' => 'The Complete Forex Trading Course',
'description' => 'An in-depth course on Forex trading strategies, risk management, and market analysis.',
'tier' => 'premium',
'price' => '149.50',
'type' => 'course',
'instructor_id' => null
]
];
$stmt = $pdo->prepare(
"INSERT INTO courses (title, description, tier, price, type, instructor_id)
VALUES (:title, :description, :tier, :price, :type, :instructor_id)"
);
foreach ($courses as $course) {
$stmt->execute([
':title' => $course['title'],
':description' => $course['description'],
':tier' => $course['tier'],
':price' => $course['price'],
':type' => $course['type'],
':instructor_id' => $course['instructor_id']
]);
}
echo "Successfully seeded the courses table.\n";
} catch (PDOException $e) {
die("Seeding failed: " . $e->getMessage());
}