Danilkalmykov Danilkalmykov - 4 months ago 6x
MySQL Question

Assigning the value to an empty field

Need to update a field in database, but when I make a request, it writes me "0 rows affected" although the image field is, and it is empty.

UPDATE `oc_product` SET `image`= 'no_image.png' WHERE `image`='';


Your query is checking for a value of an empty string, although from what you have shown the value you are actually looking to change has a value of NULL. These are two different values, NULL isn't equal to ''. As such if you are looking to replace items that have a NULL value you need to change your where statement for that (WHERE image IS NULL):

UPDATE `oc_product` SET `image`= 'no_image.png' WHERE `image` IS NULL;