开发者

Retrieve where clauses in CodeIgniter Activerecord

Is there a way to retrieve what the "where" clauses i have added in my query? I use a foreach statement to add the columns I want to add in the where clause for the current query but, since the clause could be empty (no columns added, 0 iterations in the foreach) the query would retrieve all the records in the database because no restrictions where made. Of course I could use a boolean variable to know wheter the foreach is making at least 1 iteration but I would like to know whether it is possible to retrieve information related to the quer开发者_C百科y i'm making. Sorta the code i'm using:

foreach($columns as $column => $value){
    if($column!=''){
        $this->db->where($column,$value);
    }
}
$this->db->get('mytable');

Some explanation:

If $column is an emptry string i don't add it to the query.

$columns var is an object (stdClass).

So, if there is no "where" statement in the query, I don't want to retrieve any information with $this->db->get(). What I'm looking for is something like

if( ! empty($this->db->where_clauses()))
    $this->db->get('mytable');

Is there something like that?

Thanks.


Not directly: its a bit of a hack, but you can do this:

if( ! empty($this->db->ar_where))

Try that and see if it works.


foreach($columns as $column => $value){
    if($column!=''){
        $this->db->where($column,$value);
    }
}

if (count($columns) > 0)
$this->db->get('mytable');
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜