开发者

Mixing Active Records with Standard SQL Query in Codeigniter

开发者 https://www.devze.com 2023-03-10 16:57 出处:网络
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 sq

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号