exec("CREATE TABLE IF NOT EXISTS admins ( id INT AUTO_INCREMENT PRIMARY KEY, username VARCHAR(150) UNIQUE NOT NULL, password VARCHAR(255) NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP )"); // 更新或插入管理员 $stmt = $db->prepare("SELECT id FROM admins WHERE username = ?"); $stmt->execute([$new_username]); if ($stmt->fetch()) { $stmt = $db->prepare("UPDATE admins SET password = ? WHERE username = ?"); $stmt->execute([$hashed_password, $new_username]); } else { $stmt = $db->prepare("INSERT INTO admins (username, password) VALUES (?, ?)"); $stmt->execute([$new_username, $hashed_password]); } echo "

管理员账号重置成功!

"; echo "

用户名: $new_username

"; echo "

新密码: $new_password

"; echo "

警告:请立即删除 reset_admin.php 文件!

"; echo "前往登录"; } catch (Exception $e) { echo "

重置失败:

"; echo "

" . $e->getMessage() . "

"; echo "

请检查 db/config.php 中的数据库连接配置是否正确。

"; }