Php design mode DAO (Data Access Object mode) _ PHP Tutorial

Source: Internet
Author: User
Php design mode DAO (Data Access Object mode ). Copy the code as follows :? Php *** Data Access Object (DataAccessObject) example ** @ create_date: 2010-01-04 * classBaseDAO {var $ _ dbnull; var $ _ tablenull; functionBa The code is as follows:


/**
* Data Access Object example
*
* @ Create_date: 2010-01-04
*/

Class BaseDAO
{
Var $ _ db = null;
Var $ _ table = null;

Function BaseDAO ($ config)
{
$ This-> _ db = new MysqlDB (); // operation not allowed here
}

/**
* Get and process
*
* @ Param array $ filter // filter condition
* @ Param string $ field // Obtain the 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 ();

/**
* Common usage:
* Base class of the model layer in MVC
*/
?>

The http://www.bkjia.com/PHPjc/323783.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/323783.htmlTechArticle code is as follows :? Php/*** Data Access Object example ** @ create_date: 2010-01-04 */class BaseDAO {var $ _ db = null; var $ _ table = null; function Ba...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.