How to effectively create object classes when working with table joins?

I have to start with the fact that I'm not now, and I have no illusions that I will ever be a professional programmer, so most of my skills have been learned from experience very much, like a hobby.

I learned PHP as it seemed like a good simple introduction in certain areas, and it allowed me to develop simple web applications.

When I found out about objects, classes, etc., the mentor’s basic exams covered the idea that, as a rule, each database table should have its own class. Although this worked well for the photo gallery project we wrote, because it had very simple mysql queries, it doesn't work so well that now my projects are becoming more complex. If I need data from two separate tables for which a table join is required, I instead ignored the class and processed it in each case, OR, even worse, I merged some data into a class, and the rest as a separate object and performs two queries that seems ineffective to me.

As an example, when viewing content on a forum that I wrote, if you are viewing a stream, I retrieve data from the stream table, message table, and user table. Queries from the user table and messages are retrieved via the connection and are not created as an object, while thread data is called using my Threads class.

So, how do I get something a little less “dumb” from my current state of affairs due to the lack of a better word. Right now I have a DB class that deals with connection and escaping values, etc., a parent db query class that deals with general queries and methods, and all other classes (Thread, Upload, Session, Photo and those that are not used by Mail, User, etc.) are children of this.

, , ( )?
, ? , ?
- , , , , db , , , db , , , , ?

, , , .

:

, . , , , ? ? ? - ?

+3
4

, .

: , , .

, , : ActiveRecord, ORM (Object Relational Mapper)

P.S. , . , .

() :

$post = new PublishedPost($data);
$edit = $post->setTitle($newTitle);
$edit->save();
+3

, , .

, : Table Data Gateway, , Active Record Data Mapper. php frameworks . .

, , - . - , , , " ", " ", "" .. . 200 PoEAA.

, , Doctrine Propel - PHP ORM - .

+2

, , , CakePHP, symfony Zend Framework. , . ? , , !

, , . !

+1

Source: https://habr.com/ru/post/1743422/


All Articles