Weird backticks behaviour in Active Record in CodeIgniter 2.0.3

后端 未结 9 1623
迷失自我
迷失自我 2020-12-29 06:08

Previously my all queries were running fine in CI version 2.0 but when I upgraded to 2.0.3 some of my SELECT queries were broken.

CI is adding

9条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-29 06:30

    class Company_model extends MY_Model
    {
    
    ----------------
    
    $this->db->select(" count('$fieldname') as num_stations",false);
    $this->db->select(" CONCAT_WS(',', clb_company.address1, clb_company.address2, clb_company.city, clb_company.state, clb_company.zipcode ) as companyAddress",false);
    $this->db->from($this->_table);
    $this->db->join($this->_table_device, $fieldname1. " = ".  $fieldname2, 'LEFT');
    $this->db->where($blablafield , '0');
    ----------------
    

    The false you were talking about is what is needed, can you try the code above and copy and paste to us the output of

    echo $this->db->last_query();
    

    This will show us what the DB class is creating exactly and we can see whats working / what isn't. It may be something else (you haven't given the error from that is generated sometimes sql errors can be misleading.)

    From the docs:

    $this->db->select() accepts an optional second parameter. If you set it to FALSE, CodeIgniter will not try to protect your field or table names with backticks. This is useful if you need a compound select statement.

提交回复
热议问题