Why all the SQL hate?

June 1, 2006 by alex

I’ve been trying out a few different PHP frameworks, and generally getting more familiar with full-blown OO design and development. When they talk about how much time the framework will save you, just about every one makes some kind of claim like ‘you never have to write SQL again’! What they usually mean is that the framework includes some object persistence layer that lets you insert/update/delete data via object methods rather than SQL.

I can see the benefit of this in a number of contexts, but I still have concerns.

The typical persistence layer will turn $obj->load() into something like “SELECT * FROM table”, and that’s a problem in my mind. Every time you load the object, you get EVERYTHING from the row, even if you only actually need the data from 1 column. It gets worse if the object you’re loading is spread over multiple tables - you get all data from all tables. The object makes your PHP code nice and neat, but it translates into unnecessarily large queries, and lots of unnecessary data being sent from the database to the application.

Given that database access is often the #1 bottleneck in a web application, this seems like a formula for making performance worse.

☙ ☙ ☙