Mixing Active Records with Standard SQL Query in Codeigniter
Right now I am using active records to access the database. However, an additional feature requires me to use standard SQL query. Is it po开发者_Go百科ssible to use both active records and standard sql query in the same query? Eg:
$this->db->select(...)
->from(...)
-> .....
->query(WHERE CASE ..........);
In the standard SQL query, I want to use a WHERE clause with CASE. Is this possible without rewriting the entire query in standard SQL? The active record query is very complex
As far as I know, you can't combine standard SQL and active record like you're trying to do.
However, you can write your WHERE string manually if you want, and then submit that to the ActiveRecord class. I'm not entirely sure if that's what you're looking for as I have never even used CASE, but it sounds like it might be what you're looking for? Let me know!
$where = "name='Joe' AND status='boss' OR status='active'";
$this->db->where($where);
精彩评论