Eloy Fernández Franco Eloy Fernández Franco - 1 month ago 12
MySQL Question

Codeigniter remove "(" in join clause

I am getting a problem in a join clause... this is my code:

$this->db->select("users.id, users.first_name, users.second_name")->from("users");
$this->db->join("users_groups", "users_groups.user_id=users.id AND (users_groups.group_id=".$this->config->item("admin_group")." OR users_groups.group_id=".$this->config->item("admin_location_group")." OR users_groups.group_id=".$this->config->item("employee_group").")", "INNER");
return $this->db->get()->result();

And what it produce is this:

SELECT `users`.`id`, `users`.`first_name`, `users`.`second_name` FROM `users` INNER JOIN `users_groups` ON `users_groups`.`user_id`=`users`.`id` AND `users_groups`.`group_id`=1 OR `users_groups`.`group_id`=8 OR `users_groups`.`group_id`=4)

A parenthesis before
is removed... any idea about why??

Thank you.


The Join query has a fourth optional arguement that if you set to true will not escape the data, that will stop the parser removing the brackets (and stop the escaping).

From the Docs:

join($table, $cond[, $type = ''[, $escape = NULL]]) Parameters:

    $table (string) – Table name to join
    $cond (string) – The JOIN ON condition
    $type (string) – The JOIN type
    $escape (bool) – Whether to escape values and identifiers


CI_DB_query_builder instance (method chaining)