Background: The pair of jquery has a DOM called chained operation, and PHP can use a similar method when writing SQL, such as:
/* * Get user paged album from database * * @param str|array $where query criteria * @param int $page current page * @param int $perpage number of records displayed per page * @param str $o Rder Sort Type * @param str $asc Ascending/descending * @return Array satisfies the condition of the record/public function Getusersalbumfromdb ($where, $page, $perpage, $ Order, $ASC) {$offset = ($page-1) * $perpage; $dataList = $this->getselectobj ()->where ($where)->order (er , $ASC)->limit ($perpage, $offset)->fetchobject (); return $dataList; }
This is a bit like jquery's chained notation, as follows:
$ (this). Find ("div"). CSS ("Background", "red"). End (). siblings (). Find ("div"). CSS ("Background", "green");
__call function Description: http://justwinit.cn/post/2834/
=================================================
Using the __call () method to implement database coherence operations
"", "where" = "", "order" = "" "," limit "=" "", "group" = "", "having" = > "",); The coherent operation calls the field () where () order () limit () group () method, which combines the SQL statement function __call ($methodName, $args) {//sets the first parameter Number (representing the method name that does not exist), all in lowercase, get the method name $methodName = Strtolower ($methodName); If the calling method name and the member property array $sql The subscript, the second argument is given to the element that corresponds to the subscript in the array if (Array_key_exists ($methodName, $this->sql)) {$this-&G t;sql[$methodName] = $args [0]; }else{echo ' Call class '. Get_class ($this). ' The method in the '. $methodName. ' () does not exist '; }//Return your own object, you can continue to invoke the method in this object to form a coherent operation return $this; }//output coherent operation after the combination of a SQL statement, is the last method of coherent operation function Select () {echo "Select {$this->sql[' field '} from the user {$thi s->sql[' where '} {$this->sql[' order '} {$this->sql[' limit '} {$this->sql[' group '}} {$this->s ql[' having ']} "; }} $db = new db ();//coherent Operation $db->field (' Sex, count (Sex) ')->where (' wheRe Sex in ("Male", "female") ')->group (' Group by Sex ')->having (' have AVG (age) > ')->select ();? >
----------Debugging PHP----------
Select Sex, COUNT (sex) from the user where sex in ("Male", "female") Group by sex
have avg (age) > 25
Output Completed (0 sec consumed)-Normal termination
From: http://blog.sina.com.cn/s/blog_6109978501017154.html