In the way it's written now, if my database column val already has 1 in that row, mysqli_affected_rows will return 0.推荐答案您可以使用 mysqli_info 来获取你需要区分这两种情况的信息.mysqli_info($link) 在 UPDATE 查询之后将返回一个类似You can use mysqli_info to get the information you need to distinguish between the two cases. mysqli_info($link) after an UPDATE query will return a string something likeRows matched: 1 Changed: 1 Warnings: 0然后你可以解析,例如使用 preg_match:which you can then parse, for example using preg_match:// $info = mysqli_info($link);$info = 'Rows matched: 12 Changed: 8 Warnings: 0';preg_match('/Rows matched: (\d+) Changed: (\d+)/', $info, $matches);list(, $matched, $changed) = $matches;echo "$matched rows matched, $changed rows changed\n";输出:12 rows matched, 8 rows changed然后您可以使用 $matched 和 $changed 中的值来区分您的两种情况.You can then use the values in $matched and $changed to distinguish between your two cases. 这篇关于用于 UPDATE 的 mysqli_affected_rows 有时在全行匹配时返回 0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-29 04:15