35591-vm/db/promote_user.php
Flatlogic Bot bfa71e661d 2
2025-11-09 09:57:02 +00:00

30 lines
699 B
PHP

<?php
// This script is meant to be run from the command line.
if (php_sapi_name() !== 'cli') {
die("This script can only be run from the command line.");
}
require_once __DIR__ . '/config.php';
if ($argc < 2) {
echo "Usage: php promote_user.php <email>\n";
exit(1);
}
$email = $argv[1];
try {
$pdo = db();
$stmt = $pdo->prepare("UPDATE users SET role = 'admin' WHERE email = ?");
$stmt->execute([$email]);
if ($stmt->rowCount() > 0) {
echo "User '{$email}' has been promoted to admin.\n";
} else {
echo "Could not find a user with email '{$email}'.\n";
}
} catch (PDOException $e) {
die("Database error: " . $e->getMessage() . "\n");
}