![](/img/trans.png)
[英]php mysql where statement with AND return true even if the second condition is false
[英]return true if mysql update statement excute and false when no row was updated
我有一个mysql更新语句,但是当更新行和没有更新行时它返回true。
如果行被改变,我想知道。
这是我的查询:
$q=mysql_query("UPDATE results set marks='$mark' and total='$total'
where result_id='$rid'");
if($q){
echo 'rows updated';
}
else{
echo 'No row was updated';
}
它总是打印“行更新”消息,无论是否更新记录。
任何帮助PLZ?
你可能想要mysql_affected_rows()
。
从文档:
通过与link_identifier关联的最后一个INSERT, UPDATE ,REPLACE或DELETE查询获取受影响的行数。
请注意,不推荐使用mysql_*
函数 - 我建议您切换到MySQLi或PDO (并开始使用参数化查询,以防止SQL注入 )
首先,正确的语法是:
UPDATE results
set marks='$mark', total='$total'
where result_id='$rid';
您可能希望将其标记为:
UPDATE results
set marks='$mark', total='$total'
where result_id='$rid' and marks <> '$mark' and total <> '$total';
我认为不同版本的MySQL在报告所选行是否发生变化方面存在差异,即使新版本的值与旧值相同也是如此。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.