datouboy 发表于 2014-12-15 11:40:13

求助!CodeIgniter里Mysql的replace操作的反斜杠问题

小弟想要过滤写数据库中的内容,用到了Mysql的replace语句。正常情况下面没有问题,但是遇到了含有反斜杠的内容,就不生效了。
但是Mysql语句直接在Mysql里面执行是生效的。


需要过滤的内容:\(^o^)/ \|更\|新\|最\|快|\(^o^)/

Mysql中可以生效的语句:
update `books_content` set `article_content` = replace(`article_content`,'\\(^o^)/ \\|更\\|新\\|最\\|快|\\(^o^)/','')

在CodeIgniter里语句如下(测试均不生效):
$sql = "update `dboy_books_content` set `article_content` = replace(`article_content`,'\(^o^)/ \|更\|新\|最\|快|\(^o^)/','')";
$this->db->query($sql);

$sql = "update `dboy_books_content` set `article_content` = replace(`article_content`,'\\(^o^)/ \\|更\\|新\\|最\\|快|\\(^o^)/','')";
$this->db->query($sql);
以上两种均不生效。

五体投地,跪求方法。

aqxinzhuan 发表于 2014-12-15 16:11:11

转义用下面两个函数
$this->db->escape()
$this->db->escape_str()
页: [1]
查看完整版本: 求助!CodeIgniter里Mysql的replace操作的反斜杠问题