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

[讨论/交流] $this->db->join() 不支持AND条件问题,以后的条件不加表前缀BUG..

[复制链接]
发表于 2015-3-27 13:47:01 | 显示全部楼层 |阅读模式
$this->db->join('product', 'product.productID = order_info.productID AND product.brandID = order_info.brandID','left');
不支持上面的调用方法。

改造:
class CI_DB_active_record extends CI_DB_driver{

//330行
// Strip apart the condition and protect the identifiers                if(is_array($cond)){
                    $cond_arr = $cond;
                    $cond = array();
                    foreach($cond_arr as $value){
                            if (preg_match('/([\w\.]+)([\W\s]+)(.+)/', $value, $match))
                            {
                                    $match[1] = $this->_protect_identifiers($match[1]);
                                    $match[3] = $this->_protect_identifiers($match[3]);


                                    $cond[] = $match[1].$match[2].$match[3];
     
                            }
                    }
                    $cond = implode(' AND ', $cond);
                }else{
                     if (preg_match('/([\w\.]+)([\W\s]+)(.+)/', $cond, $match))
                            {
                                    $match[1] = $this->_protect_identifiers($match[1]);
                                    $match[3] = $this->_protect_identifiers($match[3]);


                                    $cond = $match[1].$match[2].$match[3];
                            }
                }



结果:
$this->db->join('product', array('product.productID = order_info.productID','product.brandID = order_info.brandID'),'left');




大家是否觉得有必要加入该特性,或者解决 AND 以后的条件不加 表前缀的BUG。

本版积分规则