PHP / MySQL: updating a nonexistent column value

So this query:

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

returns 1, but the value "bar" does not exist in the table. As expected, nothing has changed in the database itself, but should mysql_query () not return 0 in this case?

+3
source share
3 answers

It returns truebecause the request was successful. If you want to know how many rows have been updated, you should use mysql_affected_rows.

+6
source

If you simply echo the mysql_query value, it will be true or false. You need to use mysql_affected_rows()to get the actual rows affected.

+1
source

, . , .. . - .

+1

Source: https://habr.com/ru/post/1768807/


All Articles