36884-vm/db/setup.php
Flatlogic Bot 3be72a2961 update
2025-12-12 10:37:58 +00:00

42 lines
1.2 KiB
PHP

<?php
require_once 'config.php';
try {
$pdo = db();
// Create service_requests table
$pdo->exec("
CREATE TABLE IF NOT EXISTS `service_requests` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`name` VARCHAR(255) NOT NULL,
`phone` VARCHAR(255) NOT NULL,
`address` TEXT NOT NULL,
`job_description` TEXT NOT NULL,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
");
// Create users table for admin authentication
$pdo->exec("
CREATE TABLE IF NOT EXISTS `users` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`username` VARCHAR(255) NOT NULL UNIQUE,
`password_hash` VARCHAR(255) NOT NULL
);
");
// Add a default admin user if one doesn't exist
$stmt = $pdo->prepare("SELECT id FROM users WHERE username = 'admin'");
$stmt->execute();
if ($stmt->fetch() === false) {
$pdo->prepare("INSERT INTO users (username, password_hash) VALUES (?, ?)")
->execute(['admin', password_hash('password', PASSWORD_DEFAULT)]);
}
echo "Database setup completed successfully.\n";
} catch (PDOException $e) {
die("Database setup failed: " . $e->getMessage() . "\n");
}