Talk at ZGPHP meetup #50
Video of the talk:
http://zgphp.org/videos/zgphp-stipe-predanic-achieving-the-norm-with-idiorm/
http://zgphp.org/
http://www.meetup.com/ZgPHP-meetup/events/225442690/
4. Mysqli (native extension)
● PRO
– Fast
● CON
– Hand written queries
– Rewriting all DB calls when changing database
– Not OO friendly
– Manual track of inserts and updates
6. PDO
● PRO
– Lightweight, consistent
– Can connect to different databases
– Prepared statements
– Better security through named parameters (escaped by PDO)
● CON
– still hand written SQL (different vendors have different dialects)
– still no good OO support
9. ORM
● Object relation mapping
– Object properties and their relationships are preserved
when saving to database and on load back from DB
● In short:
– Data from database table(s) are mapped to a class
– Data from classes are mapped to database table
10. ORM
● ORM does all the heavy lifting when working with databases
– Programmer just uses objects
● Searching, updating, deleting are done by simple commands
instead of using SQL
● ORM gives persistency to objects.
● Most PHP ORMs use PDO in the background
11. ORM OO patterns
● Active Record
– In-memory object carries both data and the functions
needed to work with database
● Data Mapper
– In-memory object just represents data
– Additional Mapper is used to separate database and
objects, and connects them
● One Mapper can work with several classes
13. ORM OO patterns use
● Active record
– Mostly used when object represents one or a few tables
in DB
● Database mindset
● CRUD
● Data mapper
– Mostly used when object is scattered in several tables
in DB
14. PHP ORMs
● Active Record
– Eloquent (Laravel)
– Doctrine 1
– DataMapper ORM library (CodeIgniter)
– Propel
● Data Mapper
– Doctrine 2
20. Doctrine 2
● Has relationships and way more
● Slightly higher learning curve
● But blazing fast for an ORM
21. Idiorm
● Idiorm is a deliberetely simple ORM
– Micro-ORM
– Pareto Principle
● 80% of the effects come from 20% of the causes
● Idiorm has only one class called ORM
● Uses PDO
● IS NOT A FULL ACTIVE RECORD ORM
27. Idiorm querying cont.
Taken from documentation: https://idiorm.readthedocs.org/en/latest/querying.html
Getting many in an array
Getting many in ORM objects
29. Idiorm – Active Record
● There is an Active Record implementation based on Idiorm
called Paris
From documentation
30. Conclusion
● Use ORM
– Any ORM
● Just use it
● If a programmer is experienced and uses a framework –
that framework probably uses some kind of an ORM
● Almost all of them are great!
31. Conclusion
● Idiorm is great for
– Beginners who are used to think about tables and joins
through SQL
● Usually brainwashed students
– Small projects where no special set-up is wanted or
needed
– For old projects which still uses MySQL statements, as
Idiorm is a simple drop-in solution
Notes de l'éditeur
Martin Fowler "Patterns of Enterprise Application Architecture", 2003