Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It's not that straight SQL is the devil - sometimes it's pretty much required to write raw SQL to get a query to perform the way you want it to. To me, ORMs are much more about eliminating manual work than anything else (like avoiding SQL at all costs). I just don't want to have to setup all my code objects with all hand-crafted queries for every project. That's just a ridiculous amount of work and thought. Instead, ORM tools provide a nice and automated way to create data objects that would have required a lot of manual work otherwise. Now I can have automatic individual row objects that I can extend and create custom functions for, without thinking about it. I can retrieve related rows from different tables without having to hand-code that query.</p> <p>It looks like your User class example is from <a href="http://phpdatamapper.com/" rel="nofollow noreferrer">phpDataMapper</a>, and if so, it also has some other built-in niceties like auto table migrations so you don't have to distribute an SQL file for your table structures as well as a few helper functions and other things. All features included intended to save you time - that's the main goal.</p> <p>The most important distinction between AR and DM is that an ActiveRecord (AR) row knows about it's own data store, and thus has saving/updating functions on each row object - $user->save() - The "record" is "active". With DataMapper (DM), on the other hand, each individual row does NOT know about it's own data store, by definition. The row is more of a dumb value object that can be worked with in your code. The mapper is responsible for translating the changes to that row back to the datastore - $mapper->save($user). That's the most significant difference - you will find most of the core ORM features to be the same in almost any implementation. It's just mostly a matter of how it's put together at the core architectural level.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload