The principle of building models database for PHP?

There are 3 main Paterna building models database. This Data Table Gateway, Actrive Record, Data Mapper.

I'd like to understand for what purpose is each of them to decide pros and cons.

I'm not experienced enough to make them yourself, so ask for help from Habra residents.
October 8th 19 at 01:55
3 answers
October 8th 19 at 01:57
Dear Michelle

You have the profile link to a very good book by Martin Fowler:

Her Pro Active Record:
Table Data Gateway:
Data Mapper:

Now a little reasoning from personal experience.

Binding your domain model to a relational complex based on the following factors:

* Granularity (domain model often has greater detail)
* Inheritance (need to Express in a relational data schema)
* Identity (determined by the equality but the code and ID in DB)
* Association (one-to-many is expressed in the code array in the database schema using foreign keys)
* The navigation (in the code — links in the database schema joins)

In the case that the domain model is complex, and we face many of the listed difficulties, it is recommended to use a Data Mapper. This will allow the domain objects to not worry about the existence of the database.

If the subject field is not too complex, it may be convenient to add Persistence methods to the domain model classes (Active Record). This will make it easier for programmers the process of writing the service code.

If your domain model fits well into the relational schema, but we still want to isolate the SQL for the compliance with the principle of personal responsibility, it is recommended to use a Table Data Gateway

This is a pretty common word. If you ask a question, I will be glad to clarify and reply :)
October 8th 19 at 01:59
Discussed in Skype. Now even I understand :)
Who cares — log Skype - henriette_Mante commented on October 8th 19 at 02:02
Thanks for the log. - Napoleon.Kshlerin commented on October 8th 19 at 02:05
Well done, inspired by stenography gear Gordon :) - koby_Zboncak82 commented on October 8th 19 at 02:08
October 8th 19 at 02:01
Thanks for the reply.
After reviewing the Paterno, I had a lot of questions that I can't find the answer :)
Would like to know what Paterna use in larger projects and how is this justified?
In some cases it is better to apply a particular pattern?

After using Data Mapper (Doctrine 2) I was able to allocate such
Really convenient separation logic work with the database
— Generate SQL code (CREATE TABLE)
— Realization of complex samples
— Optimization of queries
— The selection of collections
— All you need to do via the entity manager
— "Eats" lots of memory

AR pros:
— Making a DB on level up
— Ease of use
— Nevozmojnoe data hiding
— A lot of otvestvennost in the same class
— The complexity of class inheritance

Data Gateway (Zend_Table):
The rendering logic for a table in a separate class and to the top
— Work with collections (Rowset)
— It is convenient to develop the model, and everything is really flexible
— Need to create a lot of almost empty classes
— The complexity of inheritance

Do I understand correctly?
A Propel? - henriette_Mante commented on October 8th 19 at 02:04

Find more questions by tags PHPActive RecordPatterns of designing