Reputation: 4071
So, this query:
mysql_query("UPDATE item SET name = 'foo' WHERE name = 'bar'");
is returning 1, but 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?
Upvotes: 3
Views: 585
Reputation: 522342
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.
Upvotes: 1
Reputation: 6710
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.
Upvotes: 1
Reputation: 43298
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
.
Upvotes: 5