PHP design pattern DAO (data access object pattern)_PHP tutorial

WBOY
Release: 2016-07-21 15:27:25
Original
1030 people have browsed it

复制代码 代码如下:

/**
* Data Access Object Example
*
* @create_date: 2010-01-04
*/

class BaseDAO
{
var $_db = null;
var $_table = null;

function BaseDAO($config)
{
$this->_db = new MysqlDB(); // 这里的不能进行操作
}

/**
* Get processing
*
* @param array $filter // Filter condition
* @param string $field // Get field
* @param int $page // Current page
* @param int $limit // Number of pages
*/
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();

/**
* Commonly used places:
* Model layer base class in MVC
*/
?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/323783.htmlTechArticle复制代码 代码如下: ?php /*** Data Access Object (Data Access Object) Example * * @create_date: 2010-01-04*/ class BaseDAO { var $_db = null; var $_table = null; function Ba...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!