1

I have formatted all my PNG file to WebP file on my server. I need to update my database on phpMyAdmin:

images.png --> images.webp
images1.png --> images1.webp
images2.png --> images2.webp
UPDATE `gallery` SET `image_name` = '16240154071618319441c1.webp' WHERE `gallery`.`id` = 1;` ;

I have 5000 records to do.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Joe Kerr
  • 11
  • 1
  • https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_replace – Mark Rotteveel Dec 08 '22 at 14:11
  • 1
    Does this answer your question? [Find and Replace text in the entire table using a MySQL query](https://stackoverflow.com/questions/11839060/find-and-replace-text-in-the-entire-table-using-a-mysql-query) – Martin Dec 08 '22 at 14:15
  • interesting aside: webp is a very niche format that hasn't got that much traction and I think may actually be Google proprietary, whereas PNG is well established and integrated. – Martin Dec 08 '22 at 14:15

1 Answers1

0

Use replace , but I suggest specifying only the last part of the string.

UPDATE `gallery` 
SET `image_name` = replace(image_name,(right(image_name,4)),'.webp');

https://dbfiddle.uk/Iu4InO0r

The string ending with .png will be converted to .webp

Ergest Basha
  • 7,870
  • 4
  • 8
  • 28