如何检查我的 SQL 更新是否已完成?

How can I check if my SQL update has gone through?

这是我准备好的声明

 $stmt = $db->prepare("UPDATE user SET :property=:value WHERE `id`=:id");
 $stmt->execute([':property' => $property, ':value' => $value]);
 $row = $stmt->fetchAll(PDO::FETCH_ASSOC);

如何快速验证查询是否成功?

我在想也许 if() 围绕执行部分?

试试这个

if($stmt->rowCount() > 0){
   echo 'SUCCESS';
}else{
   echo 'ERROR';
}

您需要做的就是像这样测试返回的 $stmt

记住准备和执行都可能失败,应该检查

$stmt = $db->prepare("UPDATE user SET :property=:value WHERE `id`=:id");
if ( $stmt == false ) {
    print_r($db->errorInfo());
    exit;
}
$stmt->execute([':property' => $property, ':value' => $value]);
if ( $stmt == false ) {
    print_r($db->errorInfo());
    exit;
}

这个查询肯定会失败

Now I look closer, you have a huge syntax error in the query. You cannot parameterise column or table names.

You also pave 3 parameters and only 2 values