用户
 找回密码
 入住 CI 中国社区
搜索
查看: 1841|回复: 3
收起左侧

CI中使用select方法处理concat()时在第二个字段出错

[复制链接]
发表于 2014-3-30 22:52:42 | 显示全部楼层 |阅读模式
各位大神们,请问在使用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`)
请问怎么解决啊?????






发表于 2014-3-31 07:59:53 | 显示全部楼层
那就是不能这么用
你可以参考下ar模型里边的select操作
PHP复制代码
 
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;
        }
 
 
复制代码


 楼主| 发表于 2014-3-31 10:24:00 | 显示全部楼层
我知道怎么回事了!

本版积分规则