Illegal mix of collations for operation '='

2019-08-01 16:25发布

问题:

I want to select data from table 'invoice_data' where the value of company name will be choosen from the table 'crm_accounts' by value of email. I am getting error like

Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation '='

This is my model code:

public function view_invoice($email)
    {
        $this->db->select('invoice_data.*, crm_accounts.company');
        $this->db->from('invoice_data');
        $this->db->join('crm_accounts', 'invoice_data.cname = crm_accounts.company', 'inner');
        $this->db->where('crm_accounts.email', $email);
        $query = $this->db->get();
        return $query->result_array();
    }

回答1:

try this;

public function view_invoice($email)
{
    $this->db->select('invoice_data.*, crm_accounts.company');
    $this->db->from('invoice_data');
    $this->db->join('crm_accounts', 'invoice_data.cname = crm_accounts.company COLLATE utf8_unicode_ci', 'inner');
    $this->db->where('crm_accounts.email', $email);
    $query = $this->db->get();
    return $query->result_array();
}