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 possible 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);
链接地址: http://www.djcxy.com/p/7600.html

上一篇: 我如何使用自定义IHttpModule和HttpRequest过滤器来修改POST请求?

下一篇: 在Codeigniter中将活动记录与标准SQL查询混合使用