我的模型中有以下代码:
$sql = "SELECT t1.*, t2.* FROM Table1 t1 INNER JOIN Table2 t2 ON t1.id = t2.id AND t2.title IN (?) AND t1.type = ? ORDER BY t1.id";
$q = $this->db->query( $sql, array( $filter, $type ) );
问题是这个查询在以下情况下可以正常工作:
$filter = 'a';
但在以下情况下不返回任何内容:
$filter = "'a','b','c','d'";
对于第二种情况,我可以看到 CI 正在像这样逃避 $filter:
SELECT t1.*, t2.* FROM Table1 t1 INNER JOIN Table2 t2 ON t1.id = t2.id AND t2.title IN ('\'a\',\'b\',\'c\',\'d\'') AND t1.type = ? ORDER BY t1.id