<?php
namespace DbTestForChain;
class DbTestForChainOp {
public function where( $where){
$this->where = $where;
return $this;
}
public function order( $order){
$this->order = $order ;
return $this;
}
public function limit( $limit){
$this->limit = $limit ;
return $this;
}
}
$db = new DbTestForChainOp();
$query_res = $db->where(['id','1'])->order(['oder_id','desc'])->limit(10);
var_dump($query_res);
/* 【结果】
object(DbTestForChain\DbTestForChainOp)#1 (3) {
["where"]=>
array(2) {
[0]=>
string(2) "id"
[1]=>
string(1) "1"
}
["order"]=>
array(2) {
[0]=>
string(7) "oder_id"
[1]=>
string(4) "desc"
}
["limit"]=>
int(10)
}
*/
php面向对象【实现链式操作 Chain-Operation】
最新推荐文章于 2021-04-22 15:17:17 发布