Fifth Commit
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
require_once 'config/db.php';
|
||||
|
||||
try {
|
||||
$pdo = getDB();
|
||||
|
||||
// Create users table
|
||||
$sql = "
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
username VARCHAR(50) NOT NULL UNIQUE,
|
||||
password_hash VARCHAR(255) NOT NULL,
|
||||
role ENUM('admin', 'public') NOT NULL DEFAULT 'public',
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
) ENGINE=InnoDB;
|
||||
";
|
||||
|
||||
$pdo->exec($sql);
|
||||
|
||||
// Insert admin and public if not exists
|
||||
$stmt = $pdo->prepare("SELECT COUNT(*) FROM users");
|
||||
$stmt->execute();
|
||||
if ($stmt->fetchColumn() == 0) {
|
||||
$insert = $pdo->prepare("INSERT INTO users (username, password_hash, role) VALUES (?, ?, ?)");
|
||||
|
||||
// admin / admin123
|
||||
$insert->execute(['admin', password_hash('admin123', PASSWORD_BCRYPT), 'admin']);
|
||||
|
||||
// public / public123
|
||||
$insert->execute(['public', password_hash('public123', PASSWORD_BCRYPT), 'public']);
|
||||
|
||||
echo "Users created successfully.\n";
|
||||
} else {
|
||||
echo "Users table already populated.\n";
|
||||
}
|
||||
|
||||
} catch (PDOException $e) {
|
||||
echo "Error: " . $e->getMessage() . "\n";
|
||||
}
|
||||
Reference in New Issue
Block a user