- PeterMoulding.com
- Author
- Trainer
- Speaker
- Business Coach
- How to write a How To book
- PHP Courses
- Speaking
- Web Architect
- Australia
- Books
- Authors
- Akkana Peck
- Alex Berenson
- Andrew Nugent
- Ben Sanders
- Brock Clarke
- Chris Simms
- David Mercer
- Dianna Mullet
- Don Winslow
- Dori Smith
- Harlan Coben
- Jack McDevitt
- James Wines
- Jerry Yudelson
- John Grisham
- Kevin Mullet
- L. E. Modesitt Jr.
- Laurell K. Hamilton
- Marshall Karp
- Martina Cole
- Michael Marshall Smith
- Michel Roux Jr
- Nadia Sawalha
- Philip Pullman
- Raymond Khoury
- Richard North Patterson
- Robert Masello
- Sally Roth
- Sarah Langan
- Stella Rimington
- Stephen Booth
- Stephen King
- Stephen Leather
- T.C. Boyle
- Tom Negrino
- Tony Hillerman
- Urban Waite
- Val McDermid
- Valerio Massimo Manfredi
- Beginning GIMP
- Beginning Visual C++
- Culturalism
- Fiction
- A Drink Before The War
- A Talent for War
- Bag of Bones
- Blood and Ice
- Burn
- Dark Lady
- Dead Line
- Eclipse
- Empress of Eternity
- Exley
- Flipping Out
- Just One Look
- Nightfall
- Pet Sematary
- Savage Moon
- Skinwalkers
- Starvation Lake
- The Fallen
- The Gardens of the Dead
- The Jump
- The Last Templar
- The Mermaids Singing
- The Midnight Mayor
- The Secret Soldier
- The Summons
- The Terror of Living
- The Testament
- The Tower
- Under the Dome
- Virus
- AJAX and PHP
- Aging with Grace
- Food books
- Green Architecture
- Life Is So Good
- SQL: The Complete Reference
- The Backyard Bird Lover's Ultimate How-to Guide
- The Garden Gurus
- Authors
- Sustainability
- -18 hours left to decide the future of Australia
- Campbells vegetable stock or Massel vegetable stock?
- Carbon Sequestration
- Carbon tax for Australia is a fraud
- Copenhagen will fail
- Cost of living in Australia
- Dick Smith jumps on the population bandwagon
- Dry Run: Preventing the Next Urban Water Crisis
- Energy Saving Lights
- Garlic
- How many people can live in Australia?
- Its obsolete, throw it out!
- Julia Gillard offers 9.9 billion dollars bribe to Rob Oakeshott
- Laundry detergent
- Petrol or Diesel?
- Reflective foil batts kill
- RoHS
- Sea level to rise 3mm due to climate change
- Solar power
- Spring again in Sydney
- Sustainable fuels
- The CRUD Tax is back
- The people who make building regulations do not own houses
- Water efficiency
- Which insulation is safer, foil or wool?
- Will Australia reduce greenhouse gas emissions?
- Technology
- Android or Blackberry or iPhone or a flip phone?
- Apple versus Google 2011
- Cameras
- Cars
- Colour
- Burgundy
- Colour Blindness
- Colour Names
- Dulux colours
- Pantone colours
- Safe Colours
- Seculine ProDisk Mini colour balance card
- What Causes Colour Blindness?
- Hardware
- Batteries for the Digital Age
- Cables
- Cases
- Computer reliability
- Computrace
- Disks
- Astone ISO Gear 481E
- Best SSD for your notebook computer
- Disk block size
- Hitachi disk HDS722020ALA330
- LaCie USB 2.0 250 GB mobile hard drive design by F.A. Porsche
- SMART disk
- Samsung 2 TB HD204UI quiet low power disk for mass storage
- Seagate and Samsung merge disk business
- Select the right disk for your RAID array
- USB disk speed
- Western Digital WD20EARX 2 GB SATA 3 disk
- How long should computer hardware last?
- Keyboards
- Mainframe
- Memory cards
- Monitors
- Netbooks, notebooks, tablets, and xPads
- Network Attached Storage
- OLED Displays
- PC's are a thing of the past
- Printers
- Quiet
- Samsung Galaxy S
- Speed
- Television
- Tools
- USB
- Worst computer movies
- Xserve is dead. What next?
- Your backup will not work
- Z68 motherboards
- iPad or Acer Aspire One?
- IQ
- LG Intello Washing Machine
- Lack of a challenge
- Networks
- 802.11n wireless networking
- D-Link DIR-655 wireless router
- D-Link DWA-160 Xtreme N dual band USB adapter
- D-Link DWA-556 Xtreme N PCI Express desktop adapter
- MIMO
- NBN spends another $12 billion of our tax money on nothing
- National Broadband Network
- Netgear wireless modem router DGND3300 with 300 Mbps 802.11n
- Refrigerator kills wireless broadband
- Small Wireless Network
- TP-LINK TL-SG10005D 5 port gigabit switch
- TP-Link TL-WR1043N wireless N gigabit router
- Telstra Pre-paid Mobile Wi-Fi
- Where are the router plus proxy server combinations?
- Open Source documentation
- Software
- 7-zip
- Accounting
- Asterisk
- Audacity
- Backup software
- Bloat only in Windows
- CAD
- CDex
- Disk imaging software for copying and backup
- Exact Audio Copy
- Filezilla
- Firefox
- Java
- LibreOffice or OpenOffice?
- Linux
- 1 in 5 servers will ship with Linux
- Android phones outsell iPhone
- Another Move to Linux
- CentOS 5.5 installation on SSD and RAID 5
- Debian
- Debian 5.0.5 AMD64 installation
- Debian 5.06 installation
- Fedora
- Fedora or Ubuntu?
- Gnome or KDE?
- K9copy
- Linux 2.6.38
- Linux Gnome login settings lost
- Linux Mint
- Linux RAID, a rant
- Linux Speed
- Linux Time
- Linux reliability as demonstrated by Ubuntu 10.10
- Linux reliability as demonstrated by Ubuntu 11.4
- Linux still a struggle in 2011
- Linux workstation disk RAID 1
- Linux, NT, Windows, and SETI
- Linux, three years of progress
- London Stock Exchange switches to Linux
- Mandrake Linux 9.2
- The partition is misaligned by 48128 bytes - warning from Linux RAID
- Ubuntu
- How to fix the scroll bars in Ubuntu 11.4 Gnome
- Kubuntu 10.10 alternate installation on desktop with RAID 1
- POWbuntu
- Ubuntu 10.10 after 6 months use
- Ubuntu 10.10 alternate installation
- Ubuntu 10.10 desktop RAID 1
- Ubuntu 10.10 desktop RAID 5
- Ubuntu 10.10 desktop install on a netbook
- Ubuntu 10.10 desktop installation
- Ubuntu 10.10 netbook install on a netbook
- Ubuntu 10.10 server AMD64
- Ubuntu 10.10 upgrade to version 11.4 beta 2
- Ubuntu 10.4
- Ubuntu 11.10
- Ubuntu 11.10 first upgrade
- Ubuntu 11.4 after one month use
- Ubuntu 12.04 beta1 desktop amd64
- Ubuntu One
- Ubuntu by Microsoft?
- Ubuntu desktop upgrade 10.4 to 10.10 failed because I did not check the media
- Ubuntu strikes again
- Upgrade Ubuntu to Linux Mint 12 LDXE for extra speed
- Yes, use Linux but not that distribution!
- Nero
- OpenOffice
- OpenOffice is now Apache Office
- Project management
- Scribus
- Software for Windows and Linux
- Text editors
- Time
- Todo applications
- Tomboy notes
- Top text editors
- Version control
- VideoLAN VLC media player
- Visio
- Webmin
- Webmin installation on CentOS for Web development
- Webmin installation on Ubuntu
- What is the most popular open source software today?
- Windows
- Another Windows person goes Linux
- BAD_POOL_CALLER
- Cygwin
- Microsoft Malicious Software Removal Tool cannot find a common virus
- One of the developers of Windows XP is criminally insane
- There are unused icons on your desktop
- W32time
- Which Windows version?
- Windows 7 Home Premium
- Windows XP Stop 0x0000007B during installation
- Windows XP is a disaster
- Windows processes
- XML
- Zip, bzip, gzip, or 7zip?
- configFree
- Technology Succession Planning
- VoIP
- Web Sites
- Drupal
- Do Drupal themes have to use the GPL?
- Drupal 7
- A better search facility for Drupal
- Drupal - performance or flexibility
- Drupal 7 Fields are hard to fix
- Drupal 7 new features
- Drupal 7 ships on January 5
- Drupal 7.14
- Drupal 7.4 hits PeterMoulding.com
- Drupal function sequence
- The evolution of a module
- Undefined index: headers in DefaultMailSystem->mail() (line 54 of /modules/system/system.mail.inc).
- Undefined index: to in DefaultMailSystem->mail() (line 83 of /modules/system/system.mail.inc).
- implode(): Invalid arguments passed in DefaultMailSystem->format() (line 23 of /modules/system/system.mail.inc).
- Drupal 8
- Drupal Code Load Cut
- Drupal How To
- Drupal Modules
- Backup and Migrate
- Browscap
- CKEditor with Drupal WYSIWYG
- Captcha
- Cel
- Colorbox
- Content Construction Kit
- Content type
- Devel module for Drupal
- Drupal Rules as an automation language
- Drupal Spam add-on module
- Form alter to node
- IMCE
- IMCE Wysiwyg bridge
- ImageAPI
- Jdog
- Lightbox2
- Module variable
- Node Gallery Access
- Node_Gallery
- Path
- Path redirect
- Pathauto
- Pet
- Search
- Service links
- Session Variable
- Statistics
- Taxonomy
- Token
- Token ex
- Transliteration
- Trigger
- Watch
- Other modules
- Drupal Training
- Drupal access controls need a major rewrite
- Drupal coding tricks
- Drupal performance
- Drupal themes for the future
- Drupal.org colours
- Import existing data into Drupal
- Multiple Web sites made easy using Drupal multisite and the right start
- drupal_lookup_path()
- Adobe PDF
- Apache
- Apache Mahout
- Audi.com
- Bleet
- CSS Strikes Again
- CSS or xCSS
- Can you believe Facebook or email?
- Content Management Systems
- Databases
- Facebook scam
- Font
- Fonts
- HTML
- Install Apache, MySQL, and PHP 5 in Ubuntu 11.4 using the Ubuntu Software Centre
- Language Codes
- Marketing
- Memcache
- Nginx
- Open source development hits another roadblock
- Oscars
- PHP
- SPDY
- Search software
- Techoni.com.au
- Theme themes
- Things to hate on Web sites
- U.S. Patent No. 6,985,875
- Virtual Private Server
- Visible Improvement
- Web 4.0
- Web browser usage
- Web browsers
- Web site development
- Bluefish
- Crying over spilt code
- Eclipse and PHP
- Getting a Git client, a story of ancient technology and pain
- HTTrack
- MVC
- Netbeans
- PHP or ..., CakePHP/Symfony/ZF versus ...
- Programming
- Superfish
- Web browser emulators for testing your Web site
- Web development frameworks
- Web site books
- Web site development on your own computer
- Webmin or phpMyAdmin or cPanel for creating databases?
- aiki framework
- jQuery
- Views development - Learn Fields first
- Views development - Learn Actions and Rules
- jQuery .each()
- jQuery .has()
- jQuery .is()
- jQuery and Firefox Firebug
- jQuery children
- jQuery for people not using Drupal - Installation and getting started
- jQuery hover
- jQuery hover de-duplication example
- jQuery or CSS?
- jQuery performance
- jQuery tests
- Web site hosting
- Westpac Web site still broken after two years and ten months
- Wordpress wins another CMS survey
- Drupal
Doctrine or Propel for your database access code?
Submitted by Peter on Tue, 2011-09-06 18:38
Can you improve your database access code using Doctrine, Propel, or some other database access library? Doctrine and Propel are the best known varieties of software called ORM or Object Relational Mapping. ORM can make some things easier but it is not magic. You need to know what ORM does well and what it does not do.
Both Propel and Doctrine have more similarities than differences. You can study the use of either product to find out the advantages and disadvantages of ORM. There are many other ORM options but none of the others do anywhere near as much as Doctrine and Propel. Propel is described at www.propelorm.org and Doctrine at www.doctrine-project.org.
Will ORM make development faster? Your first use of ORM will not make development faster and may make development slower. You might save some time later when you are adding extra features to an existing application built using ORM.
Will ORM make development easier? The first time you use ORM, development will be more difficult while you learn how to use ORM. Doctrine has, in the past, had better documentation than Propel but learning how to use Doctrine was still difficult. There are many extra steps required to set things up initially. You have to work on an application for a while to regain the setup time. ORM can make life easier when you want to share a database design with several applications.
Will ORM make development more reliable? ORM has a real advantage when you want to share a database with several applications. You change your design once then ship the design to the other applications. Forget the problems of trying to recreate a database change in several applications.
Why use either ORM? ORM has an advantage when using complicated databases in several applications. Doctrine and Propel will do everything that you can currently do with ORM. No other ORM will give you as many advantages. If you can make use of ORM, you will use one of these ORM products. There is little point in using something less capable. The current decision is really to use one of these two ORM products or to not use ORM.
Which is better, Propel or Doctrine? The current releases of both products are close. Doctrine is faster to learn and Propel is faster to execute. Both are catching up with the other in areas where they were weak. You might have a personal preference for one based on one feature then find the other has that feature next year.
I find some Doctrine code easier to read than the equivalent Propel code but the code generated by Propel is better than the code generated by Doctrine. Native code with plain SQL is often just as easy to write and read.
The performance advantage of Propel over Doctrine is enough to make me choose Propel over Doctrine for projects running on my computer. The performance advantage of native code over both Propel and Doctrine makes me choose native code ahead of both ORM products. Code frameworks, including the Drupal CMS, save far more time than either ORM product.
Documentation
A lot of people recommend Doctine over Propel for documentation. I find some parts of Doctrine slightly easier to read but not enough to choose Doctrine based on the readability of code examples or documentation.
The last time I made a serious attempt to use Doctrine and Propel side by side was in an evaluation of Symfony for a big project. Both Symfony and Doctrine were part way through a big rewrite to version 2. The documentation for the old version was extensive but there were reasons why the old version of Symfony would not be chosen for the project and the new version was still to far away. Looking at Symfony today, Symfony with either Propel or Doctrine would be a better fit for the project but would still be down at the second or third choice, not the first choice.
The Zend framework is another contender using either Doctrine or Propel. The Zend Framework is in the middle of a big rewrite that promises serious improvements in some areas but also brings unnecessary complexity and resource wastage in other areas. You might save some time using Propel or Doctrine with Zend Framework. You will then lose the savings learning all the new stuff in the Zend framework.
In almost every case, switching to a different technology does not save time on one project because of the steep learning curve. You really need more than good documentation, you need examples very close to what you want to do. The introductory pages for both Propel and Doctrine show examples too simple to save me time, compared to hand coding, and there appears to be too much reading to get through to the point where I could solve the complex problems causing the biggest delays in the development of database based applications.
You might save time on subsequent projects if you can reuse designs and code. An example is a developer working on a series of Web sites for shops. The sites might look completely different but the structure of product details, shopping carts, and many other components will remain the same.
Performance
Every test of Doctrine versus Propel shows Propel is faster and the only argument is how fast. There are odd bits of Propel that are as slow as Doctrine and odd bits of Doctrine that are fast enough to be practical. If performance is your highest priority, hand built code is faster than either Propel or Doctrine. As a rough guide based on common application usage, Propel is twice as fast as Doctrine and hand built code is twice as fast as Propel.
Doctrine version 2 is faster than the older versions of Doctrine and there is a distinct lack of documented comparisons to help you get the best performance out of Doctrine 2 or to evaluate the overhead cost for Doctrine when you are looking at replacing existing code with Doctrine based code.
Propel has improved from release to release but not by a big amount and last year's benchmarks for Propel remain current. Propel does have some new alternatives for specifying queries and they may be faster but there are no published benchmarks.
Terminology
Here is some terminology you have to learn to keep up with ORM.
Hydration
Hydration is one of the stupid terms you have to learn when using ORM. Hydration refers to adding data to objects but has a number of conflicting uses that make hydration almost useless as a term. If you write your own native code to access data, you will learn what works then you can try to work backwards to what the ORM products do with your requests. You then find that hydration describes only the result, not the technique, and some of the techniques used in ORM software are truly primitive.
The big problem with ORM is the case where an object is built with data from several tables. How is the object built? Is the whole objected filled with data? Is the data retrieved in one request or many requests?
You might need an object for only one attribute value. The ORM software might fill/populate/hydrate the object with data from several tables, wasting huge resources, when you need only one value from the first bit of data. You have to work your way around your ORM to find out how to retrieve only what you need.
Your object might use data from several tables that can be joined to return all the data from one request. Your ORM might decide to generate several requests because ORM is not good at joining tables. Doctrine and Propel are improving but may not make the right choice for your use.
Your object might need one row from one table and several rows from another table. Think of an invoice object containing several line item rows. Your ORM might build the object the same way you would if you coded the SQL requests by hand. Now use the same object to get just the invoice total. Will your ORM optimise the object to not read the line item rows when they are not needed? This is where you have to understand all the different ways ORM software can hydrate
an object.
Your next step, for frequently used queries, is to spend a lot of time learning how to twist ORM access requests so they work efficiently, so they work the way you you would write the request if you were not forced to use ORM. Investigate the new features of the latest releases. Consider building non ORM requests for frequently used database accesses.
YAML
You might hear about YAML. YAML is a language for writing database definitions. YAML is just a distraction. YAML makes simple database definitions look simple. Complex databases look horrible when described using YAML. YAML breaks most of the good design rules you apply when designing a database or creating an application.
Frameworks
You can save application development time by using an application development framework. Some frameworks include an ORM product. You save more time using ORM with an ORM oriented framework than you save using ORM by itself.
The Symfony framework is popular and is usually used with Doctrine. You can also use Propel with Symfony but the Symfony developers push Doctrine. The Zend Framework is also popular and works with either ORM. If you want a choice of ORM, look for a framework that works with the ORM you want to use. In most cases you are better off choosing the best framework for your task then use the ORM provided with the framework because the framework will save you more time than the ORM.
Content management systems
For Web sites, a good CMS, a Content Management System, will save you more time than a framework or an ORM. If the CMS happens to use an ORM, that might help you expand the CMS to fit your requirements. Most CMS products have a database application layer but not ORM because the overheads of a CMS are already high and adding an ORM could kill the CMS.
The Drupal database abstraction layer as a comparison
Drupal has a database abstraction layer somewhere in between the PHP PDO code and Doctrine. There are similarities across the three because they use similar methods for building query objects. I could understand someone moving from Drupal to Doctrine. The original Propel query building would look backwards compared to Drupal and Doctrine. Propel now has something similar and might make the migration easier.
The current documentation for the new version of Drupal reminds me of the Doctrine documentation. There is a lot of documentation. A lot of the documentation is of high quality but is disjointed and lacks examples relevant to the problems causing the most pain. If you could combine the best of the work on Drupal and the best of the work on doctrine, the result would be strong and flexible.
Today I battled with a resource decision. I could write something to work fast but use a massive amount of memory or I could write the code to reduce memory usage by using a slower processing approach. The Drupal functions gave me a choice but not a good choice and finding the alternatives was painful. I had similar problems the last time I tried to find examples in Symfony with either Doctrine or Propel.
Both Propel and Doctrine talk about caching requests and Drupal has something similar. Both Doctrine and Propel offer alternative ways to add data to objects, hydration in their language, and Drupal does offer similar choices. The problem with Drupal is the combination of cache and hydration wasting masses of memory in situations where you do not need most of the data. Users report the same type of problem with both Propel and Doctrine. You have to be really careful how to handle large chunks of data and long lists of small data items.
There are people who know how to get the best out of the various products. There are large active Web sites built using various combinations of the different technologies. There are also a lot of serious problems ready to trap new users. I suggest you choose technology with an active friendly user community, something Drupal has in many countries.
I have not tried to get support from either the Doctrine or the propel user community. If I use either product for future projects, it will be within a framework. I will look for a framework with a strong user community and will probably use the most popular ORM option for that framework. If Drupal switches to a separate ORM, instead of continuing developing of their current approach, I prefer the performance of Propel coupled with the recent interface enhancements that make Propel coding similar to the best parts of Doctrine.
A bigger jump for Drupal would be to adopt Symfony as a framework and, in that case, Doctrine would win over Propel because it is easier to find experienced Symfony developers using the latest version of Doctrine.
There are other frameworks out there offering some shortcuts for content management system development and, in most cases, the frameworks offer more advantages that minor differences between Propel and Doctrine. Choose the framework then use the ORM recommended for the framework.
Conclusion
ORM can save you time if you spend a lot of time designing and building the database part of applications. In most other situations the overheads of learning ORM are greater than the benefits unless someone is feeding you predesigned databases you can plug in instantly using ORM.









Comments
YAML
What's wrong with YAML? For that matter what's wrong with generating YAML files from something like MySQL Workbench? Don't knock YAML, it's great for most model definitions and if your objects are too complicated to be represented in YAML there are other ways of defining your models - in PHP, through annotations, using XML to name a few.
Also, your comment about wanting only one field from a table is just silly. Picking just one or more specific fields in a query with ORM is as trivial as Doctrine_Query::create()->select('t.just_this_field')->from('thing t)
YAML is not semantic.
YAML is not semantic. Languages based on spacing and indentation do not survive email or transfer between different editors or the cut and paste you might offer to students. XML and a few other formats are safer for that reason.
YAML and other similar languages might have been widely useful back when SQL was not transportable because of Oracle incompatibility but now Oracle works with normal SQL. There are a lot of areas where data definition languages have reduced use. Productivity is determined by the tools you use to create designs and to implement applications. You choose the tools then use whatever data definition language they use. In the application development area, the framework is far more important than the ORM language. If YAML was the language of choice for a major framework and I worked only in that framework, I would use YAML. When I have to transfer specifications from one framework or tool to another, I do not want a language dependent on indentation.
Hydrating one field
One field trivial? It is one of my first tests. Select on a set of conditions and select just one or two columns for the result. Does the code process just that data or does it return whole objects? Can you see the SQL generated? I frequently find systems that return more than what is requested with the database processing overheads going through the roof.
I do not know what happens in Symfony version 2 or any of the recent version 2s. I do know that a few years ago almost every system I looked at had cases where they retrieved much more data than was requested. In some cases it was the same number of rows and too many columns. In other cases, the processing included joins to tables we did not need or unnecessary searches of unindexed fields.
I recommend testing frequently used queries to the point of showing the generated SQL and asking the database how the SQL is processed. There are a lot of times where investigation of that type has cut Web page generation back from 30 seconds to less than 0.1 second.