开发者

PHP/MySQL: Updating nonexistent column value

开发者 https://www.devze.com 2023-01-19 14:38 出处:网络
So, this query: mysql_query(\"UPDATE item SET name = \'foo\' WHERE name = \'bar\'\"); is returning 1, b开发者_高级运维ut the value \'bar\' doesn\'t exists in the table. As expected, nothing has cha

So, this query:

mysql_query("UPDATE item SET name = 'foo' WHERE name = 'bar'");

is returning 1, b开发者_高级运维ut the value 'bar' doesn't exists in the table. As expected, nothing has changed in the database itself, but shouldn't mysql_query() return 0 in that case?


It returns true, because the query was executed successfully. If you want to know how many rows were updated you have to use mysql_affected_rows.


If you are just echoing the value of mysql_query, it would be true or false. You need to use mysql_affected_rows() to get the actual affected rows.


Why, no. The query itself was successful, i.e. it was a valid query and was successfully executed. It just didn't apply to any row.

0

精彩评论

暂无评论...
验证码 换一张
取 消