ci架構 用架構內建db 添加括弧,比如 like 等等左右添加括弧 解決辦法

來源:互聯網
上載者:User

標籤:pos   site   color   產生   die   查詢   text   左右   list   

 1         $this->load->model(‘station/Station_model‘,‘Station‘); 2         // East 3         // North 4         $this->Station->set_where(‘isdel‘,0);  5         //連表查詢地區   6         $this->Station->list_attributes = ‘region.text as sitone,station.North,station.East,station.state,station.stabianhao,station.staname,station.siteonename,station.sitetwoname,station.sitename,station.statype,station.settime,station.staid‘; 7         $this->Station->join(‘region‘,‘region.linkageid = station.sitetwoname‘,‘left‘); 8         if ($type!=‘all‘) { 9             $this->Station->set_where(‘station.state‘,$type);10         }11 12         $this->Station->set_where(‘ (  station.sitetwoname‘,$sitearr,‘where_in‘);13         $this->Station->set_where(‘station.siteonename‘,$sitearr,‘or_where_in‘);14         $this->Station->set_where(‘  1 = 2 ) and 1‘,‘1‘,‘or_where_in‘);15 16         $data = $this->Station->get_stewhere_all();17         echo $this->db->last_query();die;

這樣產生的sql為

 1 SELECT 2     `dz_region`.`text` AS `sitone`, 3     `dz_station`.`North`, 4     `dz_station`.`East`, 5     `dz_station`.`state`, 6     `dz_station`.`stabianhao`, 7     `dz_station`.`staname`, 8     `dz_station`.`siteonename`, 9     `dz_station`.`sitetwoname`,10     `dz_station`.`sitename`,11     `dz_station`.`statype`,12     `dz_station`.`settime`,13     `dz_station`.`staid`14 FROM15     `dz_station`16 LEFT JOIN `dz_region` ON `dz_region`.`linkageid` = `dz_station`.`sitetwoname`17 WHERE18     `isdel` = 019 AND (20     `dz_station`.`sitetwoname` IN (21         ‘1‘,22         ‘199‘,23         ‘203‘,24         ‘197‘,25         ‘209‘,26         ‘208‘27     )28     OR `dz_station`.`siteonename` IN (29         ‘1‘,30         ‘199‘,31         ‘203‘,32         ‘205‘,33         ‘211‘,34         ‘197‘,35         ‘209‘,36         ‘208‘37     )38     OR 1 = 239 )40 AND 1 IN (‘1‘)

以上

 

如果不採用我的辦法產生的sql為

 

SELECT`dz_region`.`text` AS `sitone`,`dz_station`.`North`,`dz_station`.`East`,`dz_station`.`state`,`dz_station`.`stabianhao`,`dz_station`.`staname`,`dz_station`.`siteonename`,`dz_station`.`sitetwoname`,`dz_station`.`sitename`,`dz_station`.`statype`,`dz_station`.`settime`,`dz_station`.`staid`FROM`dz_station`LEFT JOIN `dz_region` ON `dz_region`.`linkageid` = `dz_station`.`sitetwoname`WHERE `isdel` = 0AND `dz_station`.`sitetwoname` IN (‘1‘,‘199‘,‘203‘,‘205‘,‘197‘,‘209‘,‘208‘)OR `dz_station`.`siteonename` IN (‘1‘,‘199‘,‘203‘,‘205‘,‘211‘,‘209‘,‘208‘)

  當然這是不滿足需求的,至於為什麼不用原生sql,因為數組不好處理,

ci架構 用架構內建db 添加括弧,比如 like 等等左右添加括弧 解決辦法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.