世界,您好!

欢迎使用 WordPress。这是您的第一篇文章。编辑或删除它,然后

$stmt = $pdo->query("SELECT * FROM message_attachments WHERE file_type IS NULL OR file_type = ''");
$invalidRecords = $stmt->fetchAll();

if (count($invalidRecords) > 0) {
echo "发现 ".count($invalidRecords)." 条无效记录需要修复\n";

// 3. 修复现有数据
$updateStmt = $pdo->prepare("UPDATE message_attachments
SET file_type = ?
WHERE id = ?");

foreach ($invalidRecords as $record) {
$filePath = $record['file_path'];
$mimeType = mime_content_type($filePath);

if ($mimeType === false) {
$ext = pathinfo($filePath, PATHINFO_EXTENSION);
$mimeType = getMimeFromExtension($ext);
}

$updateStmt->execute([$mimeType ?: 'application/octet-stream', $record['id']]);
echo "已修复记录ID: {$record['id']}, 文件类型: {$mimeType}\n";
}
}

echo "数据库修复完成\n";

$stmt = $pdo->query("SELECT * FROM message_attachments WHERE file_type IS NULL OR file_type = ''");
$invalidRecords = $stmt->fetchAll();

if (count($invalidRecords) > 0) {
    echo "发现 ".count($invalidRecords)." 条无效记录需要修复\n";

    // 3. 修复现有数据
    $updateStmt = $pdo->prepare("UPDATE message_attachments 
                                SET file_type = ? 
                                WHERE id = ?");

    foreach ($invalidRecords as $record) {
        $filePath = $record['file_path'];
        $mimeType = mime_content_type($filePath);

        if ($mimeType === false) {
            $ext = pathinfo($filePath, PATHINFO_EXTENSION);
            $mimeType = getMimeFromExtension($ext);
        }

        $updateStmt->execute([$mimeType ?: 'application/octet-stream', $record['id']]);
        echo "已修复记录ID: {$record['id']}, 文件类型: {$mimeType}\n";
    }
}

echo "数据库修复完成\n";



开始写作吧!

《“世界,您好!”》 有 1 条评论

  1. 您好,这是一条评论。若需要审核、编辑或删除评论,请访问仪表盘的评论界面。评论者头像来自 Gravatar

回复 一位 WordPress 评论者 取消回复

您的邮箱地址不会被公开。 必填项已用 * 标注