PHP/MySQL: Updating nonexistent column value
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.
精彩评论