简体   繁体   English

确定CodeIgniter活动记录是否设置了WHERE子句

[英]Determine if CodeIgniter active record have set a WHERE-clause

Sooo! oo! Well, the title should say most of it. 好吧,标题应该说大部分。 Are there any way to check if $this->db-where('stuff', $data) has been set previously? 有什么方法可以检查以前是否设置了$this->db-where('stuff', $data)

I could go out and make a bunch of testing of my own code (flags ect...), but I would like to know if anyone has knowledge of some fast and easy way to do it! 我可以出去对自己的代码(标志等)进行大量测试,但我想知道是否有人知道一些快速简便的方法!

Thanks in advance! 提前致谢!

[EDIT - 24-Apr-14] It's my own code. [编辑-2014年4月24日]这是我自己的代码。 I have to variable that can be null , String or an array . 我必须设置为nullStringarray变量。 They are $categories and $budget . 它们是$categories$budget So if budget is set to 100$ and category is set to stuff then I will need to use db->or_where , but if only one of them is set, I need only to use db->where . 因此,如果将预算设置为100$并且将类别设置为stuff那么我将需要使用db->or_where ,但是如果仅设置其中之一,则只需要使用db->where In this case it is quite simple just to check if first is set, but what if more values are used? 在这种情况下,仅检查是否设置了first很简单,但是如果使用更多的值怎么办? I hope you get the point :) 我希望你明白了:)

Yes you can easily determine whether a where clause is set or not. 是的,您可以轻松确定是否设置了where子句。 In CodeIgniter the Active Record class stores the wheres in an array called ar_where . 在CodeIgniter中,Active Record类将ar_where存储在名为ar_where的数组中。 You can use this array to determine if any where clauses are set or not. 您可以使用此数组来确定是否设置了where子句。

For example check the following code snippet : 例如,检查以下代码片段:

$this->db->select()
            ->from("foo")
            ->where('bar',NULL);

        $this->db->or_where('xyz',NULL);

        print_r(sizeof($this->db->ar_where));

The following will output a value of 2 . 以下将输出值2 So you can use this array to check for your result. 因此,您可以使用此数组检查结果。

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

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