读书人

展缓查询

发布时间: 2012-09-12 09:21:30 作者: rapoo

延缓查询

?

<?phpclass SelectQuery {    private $dbConn;    private $select;        public function __construct($dbConn) {        $this->dbConn = $dbConn;        $this->select = $dbConn->select();    }        public function addField($col, $value, $op = '=', $join = 'and') {};        public function getLazyEntities() {        return new LazyQuery($this, 'findAll');    };        public function getLazyEntity() {        return new LazyQuery($this, 'find');    };        public function findAll() {        return $this->dbConn->fetchAll($this->select);    }        public function find() {        return $this->dbConn->fetchRow($this->select);    }}class LazyQuery {    private $query;    private $method;        public function __construct($query, $method) {        $this->query = $query;        $this->method = $method;    }        public function execute() {        $query = $this->query;        $method = $this->method;        if ($query && method_exists($query, $method)) {            return $query->$method();        }        throw new Exception("Query failed to call method.");    }}

读书人网 >编程

热点推荐