Activity record of data source schema mode _php tutorial

Source: Internet
Author: User
Tags php example
"Intent of the activity record"

An object that wraps a row in a data table or view, encapsulates the database access, and adds domain logic to the data.

"Applicable Scenarios for Activity records"

Applies to less complex domain logic, such as CRUD operations.

"Operating mechanism of activity records"

objects have both data and behavior. It uses the most straightforward method of placing data access logic in a domain object.

The essence of an activity record is a domain model in which the records structure in the class and base database in the domain model should match exactly, and each field of the class corresponds to each column of the table.

In general, the activity record includes the following methods:

1, the data row constructs an activity record instance;

2, for the future of the insertion of the table to construct a new instance;

3, using static search method to wrap the common SQL query and return activity records;

4. Update the database and insert the data from the activity record into the database;

5, get or set the domain;

6. Realize part of business logic.

"Advantages and disadvantages of activity logging"

Advantages:

1, simple, easy to create and easy to understand.

2. Reduce code replication when using transactional scripting.

3, you can change the database structure without changing the domain logic.

4. Derivation and test validation based on a single activity record can be effective.

Disadvantages:

1. There is no hidden relational database.

2. The activity record is valid only if the active Record object corresponds directly to the table in the database.

3, the requirements of the design of the object and the design of the database tightly coupled, which makes it difficult to further reconstruct the project

"Activity records and other modes"

Data source schema mode row data entry: The activity record is very similar to the row data entry. The main difference between the two is that the row data portal has only database access and the active record has both the data source logic and the domain logic.

"PHP Example of activity log"

 
 
  1. /**
  2. * Enterprise Application Architecture Data source schema mode of activity record 2010-10-17 sz
  3. * @author phppan.p#gmail.com http://www.phppan.com
  4. * Members of the Brother Society (http://www.blog-brother.com/)
  5. * @package Architecture
  6. */
  7. /**
  8. * Order Class
  9. */
  10. class Order {
  11. /**
  12. * Order ID
  13. * @var
  14. */
  15. Private $_order_id;
  16. /**
  17. * Customer ID
  18. * @var
  19. */
  20. Private $_customer_id;
  21. /**
  22. * Order Amount
  23. * @var
  24. */
  25. Private $_amount;
  26. Public function __construct ($order _id, $customer _id, $amount ) {
  27. $this ->_order_id = $order _id ;
  28. $this ->_customer_id = $customer _id ;
  29. $this ->_amount = $amount ;
  30. }
  31. /**
  32. * Delete operations for instances
  33. */
  34. Public function delete() {
  35. $sql = "DELETE from Order SET WHERE order_id =" . $this ->_order_id. "and customer_id =" . $this ->_customer_id;
  36. return db::query ($sql);
  37. }
  38. /**
  39. * Update operation of the instance
  40. */
  41. Public function Update () {
  42. }
  43. /**
  44. * Insert Operation
  45. */
  46. Public http://www.bkjia.com/PHPjc/486087.htmlwww.bkjia.comtrue/http www.bkjia.com/PHPjc/486087.htmltecharticleAn object that wraps a row in a data table or view, encapsulates the database access, and adds domain logic to the data. "The applicable field of the activity record ...

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.