问题是当字符串包含单词“or”和“like”的组合时,事件记录语句中的字符串被转义。这是我使用的代码
$this->db->select('id');
$this->db->where('phrase', $phrase);
$this->db->from('phrases');
$ret = $this->db->get();
这适用于普通字符串,但当 $phrase 遇到像这样的字符串时失败 “点击您要使用的事件或预订代码。” 其中“或”和“喜欢”作为单词出现。
查询结果如下
SELECT `id` FROM `phrases` WHERE `phrase` = 'Click on the Event or `Booking Code you` `would` like to use.'
我不能禁用转义,因为这对其他字符串来说很方便。
最佳答案
我认为您需要在 where 子句中添加第三个参数来转义值。
$this->db->select('id');
$this->db->where('phrase', $phrase, FALSE);
$this->db->from('phrases');
$ret = $this->db->get();
来自manual :
where($key[, $value = NULL[, $escape = NULL]])
Parameters:
$key (mixed) – Name of field to compare, or associative array$value (mixed) – If a single key, compared to this value
$escape (bool) – Whether to escape values and identifiers
有关 Stack overflow 的这篇文章中有更多信息.
关于php - 奇怪的 Codeigniter 查询转义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38222291/