The phpcall () method implements database coherent operations. Background: for jquery, there is a kind of dom called chained operations. PHP can also use similar methods when writing SQL statements, such:
/** Obtain the user's album records from the database ** @ param str | array $ where query condition * @ param int $ page current page * @ param int $ perpage records displayed on each page count * @ param str $ order sorting type * @ param str $ asc ascending/descending * @ return array records that meet the conditions/public function getUsersAlbumFromDB ($ where, $ page, $ perpage, $ order, $ asc) {$ offset = ($ page-1) * $ perpage; $ dataList = $ this-> getSelectObj () -> where ($ where)-> order ($ order, $ asc)-> limit ($ perpage, $ offset)-> fetchObject (); return $ dataList ;}
This method is similar to Jquery's chained method, as follows:
$ (this).find ("p").css ("background", "red").end().siblings ().find ("p").css ("background", "green");
_ Call function introduction: http://justwinit.cn/post/2834/
========================================================== ==========
Use the _ call () method to achieve consistent database operations
"", "Where" => "", "order" => "", "limit" => "", "group" => "", "having" => "",); // call the field () where () order () limit () group () having () method, combined SQL statement function _ call ($ methodName, $ args) {// convert the first parameter (representing the method name without a method) to lowercase, GET method name $ methodName = strtolower ($ methodName); // If the called method name corresponds to the member attribute array $ SQL subscript, the second parameter is given to the element if (array_key_exists ($ methodName, $ this-> SQL) corresponding to the subscript in the array )) {$ this-> SQL [$ methodName] = $ args [0];} else {Echo 'Call class '. get_class ($ this ). 'method in '. $ methodName. '() does not exist';} // returns your own object, you can continue to call the methods in this object to form a consistent operation return $ this ;} // an SQL statement that is combined after a coherent operation is output. it is the final method of a coherent operation, function select () {echo "SELECT {$ this-> SQL ['field']} FROM user {$ this-> SQL ['where']} {$ this-> SQL ['order'] }{$ this-> SQL ['limit'] }{$ this-> SQL ['group'] }{$ this-> SQL ['having']} "; }} $ db = new Db (); // coherent operations $ db-> field ('sex, count (sex) ')-> where ('Where sex in ("male "," Female ") ')-> group ('group by sex')-> having ('Having avg (age)> 25')-> select ();?>
---------- Debug PHP ----------
SELECT sex, count (sex) FROM user where sex in ("male", "female") group by sex
Having avg (age)> 25
Output completed (0 sec consumed)-Normal Termination
From: http://blog.sina.com.cn/s/blog_6109978501017154.html