phpmyadmin 在嵌套的json表中查找和替换字符串(MySql)

qkf9rpyu  于 2023-10-20  发布在  PHP
关注(0)|答案(1)|浏览(214)

我有一个问题,我一直试图解决,但不幸的是无法解决。我有一个嵌套的json数据在一个名为“fields”的列中:

{"15":{"name":"field1","value":"http:\/\/randomwebsite.com\/wp-content\/uploads\/wpforms\/8231-9dfa327b1cf628635799d85de588101b\/test1.pdf","value_raw":[{"name":"test.pdf","value":"http:\/\/randomwebsite.com\/wp-content\/uploads\/wpforms\/8231-9dfa327b1cf628635799d85de588101b\/test1.pdf","file":"test1.pdf","file_original":"test.pdf","ext":"pdf","attachment_id":0,"id":15,"type":"application\/pdf"}],"id":15,"type":"file-upload","style":"modern"}

这里我想用“https://rightwebsite.me“替换“ http://randomwebsite.com“我试过这个查询:

UPDATE mytable
SET fields = REPLACE(fields, 'http:\/\/randomwebsite.com', 'https:\/\/rightwebsite.me')
WHERE fields LIKE '%"http:\/\/randomwebsite.com%';

我甚至尝试使用JSON_EXTRACT,但我得到了这个错误:

#1305 - FUNCTION 111111_wp2.JSON_EXTRACT does not exist

但是没有用。有人可以帮助我如何在phpmyadmin中更新嵌套的json吗?

db2dz4w8

db2dz4w81#

第一步,你必须退出MySQL的安全模式

SET SQL_SAFE_UPDATES = 0;
UPDATE mytable
SET `fields` = REPLACE(fields, 'http:\/\/randomwebsite.com', 'https:\/\/rightwebsite.me')
WHERE `fields` like '%http:\/\/randomwebsite.com%' ;
SET SQL_SAFE_UPDATES = 1;

然后u可以修改MySQL中的行

相关问题