发现始终无法匹配到正确的数据,查阅了一下百度相关MYSQL特殊符号数据查询说明,发现下划线的表达为like '%_%' 就是前面用斜杠转义下,果然就可以了!
- $query="select * from phome_enewsclass where bname like '%_%' order by classid desc";
完整PHP代码如下:放到/e/extend/文件访问,文件名随意。
- <?php
- define('EmpireCMSAdmin','1');
- require("../class/connect.php");
- require("../class/db_sql.php");
- require("../class/functions.php");
- require("../class/t_functions.php");
- require("../data/dbcache/class.php");
- require("../data/language/gb/pub/fun.php");
- $link=db_connect();
- $empire=new mysqlquery();
- $editor=1;
- $username='';
- $query="select * from phome_enewsclass where bname like '%_%' order by classid desc";
- $sql=$empire->query($query);
- while($r=$empire->fetch($sql))
- {
- $new_bname=str_replace('_',' - ',$r[bname]);
- echo ''.$r[classid].'--'.$r[bname].'--'.$new_bname.'<br>';
- $empire->query("update phome_enewsclass set bname='$new_bname' where classid='$r[classid]'");
- }
- db_close();
- $empire=null;
- ?>