CI中使用select方法处理concat()时在第二个字段出错
各位大神们,请问在使用select方法组装sql语句是,代码如下$this->db->select('concat(user_id,product_id)')->distinct();
return $this->db->from("logs")->get()->result_array();
在运行时出来的sql语句老是在第二个地段即product_id加了一个单引号,从而导致sql语法出错,sql语句如下:
SELECT DISTINCT concat(user_id, `product_id)` FROM (`logs`)
请问怎么解决啊?????
那就是不能这么用
你可以参考下ar模型里边的select操作
public function select($select = '*', $escape = NULL)
{
if (is_string($select))
{
$select = explode(',', $select);
}
foreach ($select as $val)
{
$val = trim($val);
if ($val != '')
{
$this->ar_select[] = $val;
$this->ar_no_escape[] = $escape;
if ($this->ar_caching === TRUE)
{
$this->ar_cache_select[] = $val;
$this->ar_cache_exists[] = 'select';
$this->ar_cache_no_escape[] = $escape;
}
}
}
return $this;
}
我知道怎么回事了!
注意括弧
页:
[1]