Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 900
Nyxynyx Avatar asked Jun 04 '11 23:06

Nyxynyx


1 Answers

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);
like image 88
Joris Ooms Avatar answered Sep 28 '22 06:09

Joris Ooms