Codeigniter Activerecord: Join Backticking

Codeigniter ActiveRecord: join backticking

Only a simple workaround, ugly, not elegant, but it works in this case:

$original_reserved = $this->db->_reserved_identifiers;
$this->db->_reserved_identifiers[] = 5;
$this->db->_reserved_identifiers[] = 1;
// or any other values
$this->db->join('with critical values and conditions');
// some db-stuff
$this->db->_reserved_identifiers = $original_reserved;

If anybody knows better please show it!

Complex where/join statement with codeigniter across several tables

You could set the third parameter of where() method to FALSE to prevent CI from adding backticks to table/field names.

From CI doc:

$this->db->where() accepts an optional third parameter. If you set it
to FALSE, CodeIgniter will not try to protect your field or table
names with backticks.

As follows:

$this->db->where($where, NULL, FALSE);

how do i ignore the backticks in codeigniter when using active records? i need to order by cases

Thanks for your answers...

I figured out that in active records when using $this->db->order_by() you can't skip the backticks.

So ended up using $this->db->query($sql); where I assigned my normal mysql query to the $sql variable

mysql | Codeigniter Active Records are adding extra back ticks to query

Add a second parameter FALSE in your SELECT()

So,

$this->db->select("
T.id AS TimeSheetID,
DATE_FORMAT(T.date_created,'%M') AS MonthName", FALSE);

$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.

Reference

How to avoid ` when multiple conditional join in codeigniter?

Last join argument allow to skip escape condition with "`"

/**
* Join
*
* Generates the JOIN portion of the query
*
* @param string
* @param string the join condition
* @param string the type of join
* @param string whether not to try to escape identifiers
* @return object
*/
public function join($table, $cond, $type = '', $escape = NULL)

Thanks Michael!

Buggy joins on CodeIgniter ActiveRecord

$this->db->join(
'predict',
"(predict.id_predict = portion.id_predict AND `event`.`id_event` = 5)",
'left'
);

are you looking for this ?

EDIT

$this->db->join('predict', "predict.id_predict = portion.id_predict", 'left');
$this->db->where('event.id_event = 5');


Related Topics



Leave a reply



Submit