Welcome Guest, Not a member yet? Register   Sign In
dbprefix does not work with joins
#1

(This post was last modified: 04-11-2015, 05:40 PM by codeignites.)

Hi Folks,

I have created two tables in my database called company_db

cp_branches
cp_emp

I have set dbprefix as cp_ in config > database.php

when I run the following query, I get Table 'company_db.emp' doesn't exist error.
PHP Code:
$this->db->start_cache(); 
$this->db->join('emp as e''e.emp_id = branches.bran_added_by''left'false);
$this->db->stop_cache();
 
$data->count $this->db->count_all_results('branches');
 
$this->db->select('bran_id, bran_name, bran_abbreviation, bran_mobile, bran_phone, bran_email, bran_status, bran_order_by, bran_added_date, concat(emp_fname, " ", emp_lname) as emp_name'false);
$this->db->order_by('bran_order_by''desc');
$query $this->db->get('branches');
$data->result $query->result();
 
$this->db->flush_cache(); 

Error Number: 1146

Table 'company_db.emp' doesn't exist

SELECT bran_id, bran_name, bran_abbreviation, bran_mobile, bran_phone, bran_email, bran_status, bran_order_by, bran_added_date, concat(emp_fname, " ", emp_lname) as emp_name FROM `cp_branches` LEFT JOIN emp as e ON e.emp_id = branches.bran_added_by ORDER BY `bran_order_by` DESC


dbprefix is not added to table names in join function.
Am I missing anything here?

Same code works fine in Codeigniter 2.x.
Reply
#2

The db prefix is added while escaping the query, so passing false as the 4th argument to $this->db->join() is preventing the addition of the prefix. You couldn't prevent Active Record from escaping a join clause, so this argument didn't exist in CI 2.x.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB