简体   繁体   中英

PHP/MySQL: Updating nonexistent column value

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?

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, ie it was a valid query and was successfully executed. It just didn't apply to any row.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM