Home  >  Article  >  Backend Development  >  PHP design pattern DAO (data access object pattern)

PHP design pattern DAO (data access object pattern)

高洛峰
高洛峰Original
2016-11-30 09:35:341444browse

Data Access Object (Data Access Object) example, friends who learn PHP can refer to it.

The code is as follows:

<?php 
/** 
* 数据访问对象(Data Access Object) 示例 
* 
* @create_date: 2010-01-04 
*/ 
class BaseDAO 
{ 
var $_db = null; 
var $_table = null; 
function BaseDAO($config) 
{ 
$this->_db = new MysqlDB(); // 这里的不能进行操作 
} 
/** 
* 获取处理 
* 
* @param array $filter // 过滤条件 
* @param string $field // 获取字段 
* @param int $page // 当前页 
* @param int $limit // 页数 
*/ 
function fetch($filter = array(),$field = "*",$page = 1,$limit = null) 
{ 
$this->_db->select($filed)->from($this->_table)->where($filter)->limit($page,$limit); 
return $this->_db->execute(); 
} 
function update(){} 
function delete(){} 
function insert(){} 
} 
class MemberDAO extends BaseDAO 
{ 
var $_table = "member"; 
} 
$oMember = new MemberDAO(); 
$oMember->fetch(); 
/** 
* 常用到的地方: 
* MVC中model层基类 
*/ 
?>


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:PHP file uploadNext article:PHP file upload