PHP Design Pattern Series-Data Access object mode

Source: Internet
Author: User

    • Data Access Object mode

The data Access object pattern describes how to create objects that transparently access the data source.

    • Scene design
  1. Design a Basedao base class to implement some basic query,insert,update methods of database operation
  2. In the actual use of the process, inherit Basedao, you can directly call the base class database operation method
    • Code: Basedao Database Operations base class
<?PHP//data Access Object mode//separate the database access layer as a common access interface, user-friendly, is a common design pattern in PHP          classBasedao {Private $db;  Public function__construct ($config) {               $this->db =mysql_connect($config[' User '],$config[' Pass '],$config[' Host ']); mysql_select_db($config[' Database '],$this-db); }                     Public functionQuery$sql) {              return mysql_query($sql,$this-db); }      }  

Code: Userdao Data manipulation of user data tables, inheriting Basedao

<?PHPinclude("userdao.php"); classUserdaoextendsBasedao { Public functionAddUser () {$sql= "INSERT into user (username) VALUES (' initphp ')"; return $this->query ($sql); }      }            $UserDao=NewUserdao; $UserDao->adduser ();

Transferred from: http://blog.csdn.net/initphp/article/details/7678831

PHP Design Pattern Series-Data Access object mode

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.