35251-vm/db/seed.php
Flatlogic Bot c1d245a403 1
2025-10-26 16:30:02 +00:00

28 lines
1.1 KiB
PHP

<?php
require_once __DIR__ . '/config.php';
function seed_customers() {
$pdo = db();
$customers = [
['name' => 'John Doe', 'email' => 'john.doe@example.com', 'plan' => 'Premium HD', 'status' => 'Active'],
['name' => 'Jane Smith', 'email' => 'jane.smith@example.com', 'plan' => 'Basic', 'status' => 'Active'],
['name' => 'Mike Johnson', 'email' => 'mike.j@example.com', 'plan' => 'Premium HD', 'status' => 'Suspended'],
['name' => 'Sarah Williams', 'email' => 'sarah.w@example.com', 'plan' => 'Family Pack', 'status' => 'Deactivated'],
];
$stmt = $pdo->prepare("INSERT INTO customers (name, email, plan, status) VALUES (:name, :email, :plan, :status) ON DUPLICATE KEY UPDATE name=VALUES(name), plan=VALUES(plan), status=VALUES(status)");
foreach ($customers as $customer) {
echo "Seeding customer: " . $customer['name'] . "...\n";
try {
$stmt->execute($customer);
echo "Success.\n";
} catch (PDOException $e) {
echo "Error seeding customer " . $customer['name'] . ": " . $e->getMessage() . "\n";
}
}
}
seed_customers();