好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

dedecms SQL命令运行器批量替换指定字符串例子 -

dedecms SQL命令运行器批量替换指定字符串例子

几年前做的一个QQ站现在把资料整过来了,但是发现有些litpic缩略图中的路么地址不对了,以前我都是使用phpmyadmin替换,今天我发现可以直接使用SQL命令运行器来解决,下面来看我一个替换litpic中指定路径地址吧.

查询指定 archives 表:

这个表是主表了,我们查询一条出来看看,结果如下.

运行SQL:select * from 你的表前缀_archives where id =1466,共有1条记录,最大返回100条.

记录:1  id:1466  typeid:110  typeid2:0  sortrank:1238913636  flag:c,p  ismake:1  channel:1  arcrank:0  click:33119  money:0  title:可爱的动态nomoQQ表情图片  shorttitle:  color:  writer:  source:  litpic:http://upload.phpfensi.com/allimg/c090405/123Y13349440-1SH6.jpg  pubdate:1238913636  senddate:1238913636 

现在我们可以锁定到id =1466 记录:

select litpic from 你的表前缀_archives where id =1466;

执行结果:

运行SQL:select litpic from 你的表前缀_archives where id =1466;,共有1条记录,最大返回100条.

litpic:http://upload.phpfensi.com/allimg/c090405/123Y13349440-1SH6.jpg

好了现在我们需要把litpic 字段中的http://upload.phpfensi.com 替换成 /uploads/ 这种,这些我们可以使用update replace来实现.

我们来执行看看结果,成功执行1个SQL语句,好现在我们来查询一下执行结果是不是我们想要的,再执行:

select litpic from 你的表前缀_archives where id =1466;

确定执行提示:

运行SQL:select litpic from 你的表前缀_archives where id =1466;,共有1条记录,最大返回100条.

litpic:/uploads/allimg/c090405/123Y13349440-1SH6.jpg

看提示没有错误,我们在地址栏看看图片正确,查看是没有问题了,现在我们来批量替换.

select litpic from 你的表前缀_archives where litpic like '%http://upload.phpfensi.com%'

这样我们查一下是为了防止后面替换不会替换没有http://upload.phpfensi.com了,也防止了sql出错导致数据库全部替换掉了.

update 你的表前缀_archives set  `litpic`=replace(litpic, 'http://upload.phpfensi.com', '/uploads')  where litpic like '%http://upload.phpfensi.com%'

成功执行1个SQL语句,我们再查一下看.

运行SQL:select litpic from 你的表前缀_archives where litpic like '%http://upload.phpfensi.com%',无返回记录!

查看更多关于dedecms SQL命令运行器批量替换指定字符串例子 -的详细内容...

  阅读:52次