Reputation: 301
How to make this query below with CodeIgniter database ActiveRecord?
SELECT *
FROM `request`
WHERE (`requestedID` = 42 OR `challengerID` = 42)
AND (`requApprove` = 1 AND `challApprove` = 1);
I tried many patterns.. but it didn't work.
I can't understand how to use CI AR methods to build this query which contains parentheses.
Upvotes: 0
Views: 508
Reputation: 99504
From CI doc:
$this->db->where()
accepts an optional third parameter. If you set it toFALSE
, CodeIgniter will not try to protect your field or table names with backticks.
So, the needed AR methods would be:
$this->db->select('*');
$this->db->from('request');
$this->db->where('(requestedID = 42 OR challengerID = 42)', NULL, FALSE);
$this->db->where('(requApprove = 1 AND challApprove = 1)', NULL, FALSE);
$query = $this->db->get();
Upvotes: 1