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
What Is the Significance of Application Key in a Laravel Application
Patterns for PHP Multi Processes
PHP Static Method Call with Variable Class Name and Namespaces
Change "Billing Details" Text to "Shipping Details" on Woocommerce Checkout Page
Class App\Http\Controllers\Usercontroller Does Not Exist
Parsing Extremely Large Xml Files in PHP
How to Allow a User to Download a File Which Is Stored Outside of the Webroot
How to Stop Including a PHP File
Protect the Excel File Using PHPexcel
Display Price on Add to Cart Button from the Functions.PHP File in Woocommerce
Alternative for Deprecated PHP Function: Eregi_Replace
Restrict Content Access to Logged in Users with PHP
How to Remove Values from an Array in PHP
Set Multiple='False' in a Form in a Many to Many Relation Symfony2
PHP - Override Existing Function
Model->Save() Not Working in Yii2
Attach Image to Facebook Event (PHP Sdk, Rest or Graph API)
Preparing a MySQL Insert/Update Statement with Default Values