php設(shè)計模式 DAO(數(shù)據(jù)訪問對象模式)
更新時間:2011年06月26日 11:23:20 作者:
數(shù)據(jù)訪問對象(Data Access Object) 示例 ,學習php的朋友可以參考下。
復制代碼 代碼如下:
<?php
/**
* 數(shù)據(jù)訪問對象(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 // 頁數(shù)
*/
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層基類
*/
?>
相關(guān)文章
ThinkPHP使用心得分享-ThinkPHP + Ajax 實現(xiàn)2級聯(lián)動下拉菜單
聯(lián)動菜單的數(shù)據(jù)存在數(shù)據(jù)庫,可以隨時通過對數(shù)據(jù)庫添加刪除修改改變菜單數(shù)據(jù),而不需修改代碼,同時,實現(xiàn)了2級后,也可以實現(xiàn)3級,4級。。。等關(guān)聯(lián)菜單2014-05-05

