简体   繁体   English

在 Codeigniter 中使用标准 SQL 查询混合 Active Record

[英]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.但是,附加功能要求我使用标准 SQL 查询。 Is it possible to use both active records and standard sql query in the same query?是否可以在同一个查询中同时使用活动记录和标准 sql 查询? Eg:例如:

$this->db->select(...)
         ->from(...)
         -> .....
         ->query(WHERE CASE ..........);

In the standard SQL query, I want to use a WHERE clause with CASE.在标准 SQL 查询中,我想使用带有 CASE 的 WHERE 子句。 Is this possible without rewriting the entire query in standard SQL?如果不重写标准 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.据我所知,您不能像您尝试做的那样将标准 SQL 和活动记录结合起来。

However, you can write your WHERE string manually if you want, and then submit that to the ActiveRecord class.但是,您可以根据需要手动编写 WHERE 字符串,然后将其提交给 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?我不完全确定这是否是您要寻找的东西,因为我什至从未使用过 CASE,但听起来它可能就是您要寻找的东西? Let me know!让我知道!

$where = "name='Joe' AND status='boss' OR status='active'";

$this->db->where($where);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM