Php design mode: data object ing mode; php design mode: PHP Tutorial

Source: Internet
Author: User
Php design mode: data object ing mode; php design mode. Php design mode: data object ing mode; php design mode: data object ing mode: maps objects and data storage, operations on an object are mapped to the php design mode for data storage. data object ing mode, php design mode

The data object ing mode maps objects and data storage. operations on an object are mapped to operations on data storage.

Implement the data object ing mode in the code, implement an ORM class, and map complex SQL statements into object attributes. Object Relational ING (ORM)

Ha_cl table

Hacl. php

     function __construct($id){        $this->db = new \Baobab\Database\Mysqli();        $this->db->connect('127.0.0.1', 'root', '', 'test');        $res = $this->db->query("select * from ha_cl where id = {$id}");        $data = $res->fetch_assoc();        $this->id = $data['ID'];        $this->haclname = $data['ha_cl_name'];        $this->haclcode = $data['ha_cl_code'];        $this->hacls = $data['hacls'];    }    function __destruct(){        $this->db->query("update ha_cl set                          ha_cl_code = '{$this->haclcode}',                          ha_cl_name = '{$this->haclname}',                          hacls = '{$this->hacls}'                          where ID = {$this->id}                          limit 1");    }}

Factory. php

 

Register. php

  

Index. php

Class Page {function index () {$ hacl = Baobab \ Factory: getHacl (13); $ hacl-> haclname = 'Test name'; $ this-> test (); echo 'OK';} function test () {$ hacl = Baobab \ Factory: getHacl (13); $ hacl-> hacls = 'Test content ';}} $ page = new Page (); $ page-> index ();

In factory mode, object Hacl is created multiple times, which wastes resources. If an object is passed as a parameter, on the one hand, additional costs are incurred, in addition, if this object is used in many places, errors may easily occur. Therefore, use the registration tree mode in Factory mode to solve this problem.

Data object ing mode. php design mode: the data object ing mode maps objects and data storage. operations on an object are mapped to data storage...

Related Article

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.