Book review: Learning PHP Data Objects by <i>Dennis Poppel</i>

Book review: Learning PHP Data Objects by Dennis Poppel


Learning PHP Data Objects by Dennis Popel (Packt Publishing, 2007) introduces the PHP5 extension PDO. If you've ever worked on a LAMP server, you must know how tedious it is to go through the results of an SQL query, and to manage the connection--even worse, if you happen to change database, your work is pretty much lost: PostgreSQL, MySQL and SQLite don't have the same driver nor functions! Not so with PDO.

Get your classes and objects ready: PDO will make using a database under PHP5 a snap.

The book's coverThe book's cover

The book is a short introductory manual of approximately 200 pages. Although it's not small print, the non-justified font, "greasy" printing and the absence of line spacing make it slightly uncomfortable to read and sometimes a bit confusing. It's fine to read, but it's also not as good as Eyrolle's or O'Reilly's books.

Most of the code in the book is available through the editor's website.

It is still quite readable, but not as good as Eyrolle's or O'Reilly's books.

The contents

The book is 200 pages, with 10 pages of credits, details and table of content. It has a preamble, 7 chapters and an appendix spanning in total 180 pages, and ends with an index and some advertising for other books from the same publisher. The cover is the only piece of colour in the whole book. Screen captions are black and white, made on Firefox.

As it is a beginner's book, it starts with explaining how data is traditionally handled under PHP; other PHP libraries are presented, some more powerful than PDO; however, PDO is especially interesting due to the fact that it's compiled C++, and therefore faster than script-based PHP libraries. After presenting PDO, it uses small examples depicting how to perform the same operation on PostgreSQL, MySQL and SQLite--and then the equivalent on PDO.

PDO is entirely object oriented, and knowledge of Object-Oriented Programming (OOP) soon becomes a requirement. If you're not familiar with OOP, the book gives you as its annex a quick introduction to PHP5's OOP philosophy and syntax--you may want to start here, otherwise the rest of the book won't make much sense past the initial database connection.

While dealing with databases, establishing a connection is only the first step: you also need to handle errors. PDO can use exceptions to signal an error (which are handled though try... catch statements). To explain how to handle errors the book provides first a simple example, and then a glimpse of how it would look on a "real" application. You can also use exception handlers for uncaught exceptions, although this should not be used as the main error handling mechanism: you should secure sensitive parts of your application with try...catch statements, and use exception handler to catch "impossible" errors. Along the way, you also get an explanation of meta-data management through PDO.

Prepared statements are the next big thing. If you've ever dealt with regular expressions, you know that they are much faster when pre-compiled; the same applies to SQL queries. Simply put, prepared statements are functions (turned into object methods) that can alter an SQL query without having to generate it completely on each and every run.

Next the book explains how to handle data blobs (encoded images to be stored in databases, for example) and row sets. This is not rocket science, but it's used often enough that detailed coverage is welcome. The book ends with "advanced" performance and management tricks such as configuration file auto-loading and pre-buffered queries, and an advanced example.

Who’s this book for?

All those other part-time PHP programmers out there who got started under PHP4 and want to make their web sites more powerful and more flexible database-wide should read this book. Things like prepared statements are as important as MySQL 5's stored procedures; meta-data management is just too nice to pass up, and object-oriented data management makes it just that much less awkward to manage datasets along with the rest of the application's data.

object-oriented data management makes it just that much less awkward to manage datasets along with the rest of the application's data

This book may also help advanced PHP programmers change the habits they acquired under PHP4, but a more advanced book would serve them well if they intend to spend a lot of time on PDO. Learning PHP Data Objects is too fast a read and not enough "power-user oriented" to be of much use for that crowd.

Relevance to free software

This book uses only free software, both for programming and for screen capture; you can use it on a 100% free system without any problems.

Pros

The time you will save while working on a web site will be make the time spent reading this book well worthwhile. It's also very affordable (less than $40 or £25).

Cons

If you're a power PHP user, it won't hold your attention for more than a couple hours. You'd be better off borrowing it, and then get an "advanced" equivalent.

Title Learning PHP Data Objects
Author Dennis Popel
Publisher Packt Publishing
ISBN 9781847192660
Year 2007
Pages 200
CD included No
FS Oriented 10
Over all score 8.5

In short

Category: 
Tagging: 
License: 

Author information

Mitch Meyran's picture

Biography

Have you ever fixed a computer with a hammer, glue and a soldering iron? Why not? It's fun!

Most forwarded

Interview with Dave Mohyla, of DTIDATA

Dave Mohyla is the president and founder of dtidata.com, a hard drive recovery facility based in Tampa, Florida.

TM: Where are you based? What does your company do?
DTI Data recovery is based in South Pasadena, Florida which is a suburb of Tampa. We have been here for over 10 years. We operate a bio-metrically secured class 100 clean room where we perform hard drive recovery on all types of hard disks, from laptop hard drives to multi drive RAID systems.

Anybody up to writing good directory software?

Since the very beginning, directories (of any kind) have had a very central role in the internet. (I have recently grown fond of Free Web Directory. Even Slashdot can be considered a directory: a collection of great news and invaluable user-generated comments. As far as software is concerned, doing a quick search on Google about software directories will return the free (as in freedom) software directories like Savannah, SourceForge, Freshmeat and so on, followed by shareware and freeware sites such as FileBuzz, PCWin Download Center and All Freeware (great if you're looking for shareware and freeware, but definitely less comprehensive than their free-as-in-freedom counterparts).

Interview with Mark Shuttleworth

Mark Shuttleworth is the founder of Thawte, the first Certification Authority to sell public SSL certificates. After selling Thawte to Verisign, Mark moved on to training as an astronaut in Russia and visiting space. Once he got back he founded Ubuntu, the leading GNU/Linux distribution. He agreed on releasing a quick interview to Free Software Magazine.

Is better education the key to finding better software?

I read David Jonathon's article Anybody Up To Writing Good Directory Software? the other day, which got me thinking about software directories in general. As David mentioned, many of the software directories one finds when doing a quick google search are free as in beer, not as in freedom. But what interests me is the software directories that already exist, providing a combination of both free as in beer software, and open source software. Sites such as Freeware Downloads and Shareware Download don't advertise themselves as providing free as in liberty software, but each of them have a good selection of open source software available... if you know where to look.

Most emailed

Free Open Document label templates

If you’ve ever spent hours at work doing mailings, cursed your printer for printing outside the lines on your labels, or moaned “There has got to be a better way to do this,” here’s the solution you’ve been looking for. Working smarter, not harder! Worldlabel.com, a manufacture of labels offers Open Office / Libre Office labels templates for downloading in ODF format which will save you time, effort, and (if you want) make really cool-looking labels

Creating a user-centric site in Drupal

A little while ago, while talking in the #drupal mailing list, I showed my latest creation to one of the core developers there. His reaction was "Wow, I am always surprised what people use Drupal for". His surprise is somehow justified: I did create a site for a bunch of entertainers in Perth, a company set to use Drupal to take over the world with Entertainers.Biz.

Update: since writing this article, I have updated the system so that the whole booking process happens online. I will update the article accordingly!

So, why, why do people and companies develop free software?

More and more people are discovering free software. Many people only do so after weeks, or even months, of using it. I wonder, for example, how many Firefox users actually know how free Firefox really is—many of them realise that you can get it for free, but find it hard to believe that anybody can modify it and even redistribute it legally.

When the discovery is made, the first instinct is to ask: why do they do it? Programming is hard work. Even though most (if not all) programmers are driven by their higher-than-normal IQs and their amazing passion for solving problems, it’s still hard to understand why so many of them would donate so much of their time to creating something that they can’t really show off to anybody but their colleagues or geek friends.

Sure, anybody can buy laptops, and just program. No need to get a full-on lab or spend thousands of dollars in equipment. But... is that the full story?

Fun articles

Santa Claus - the most successful open source project

It dawned on me the other day, as I was shopping for the dozens of gifts it seems I have to buy every December, that Santa Claus is the most successful open source project in history. (Bridget @ Illiterarty would agree with that). Santa Claus is essentially a marketing development that is embodied by everyone who stuffs a sock, gives a gift, hosts a dinner or wishes Merry Christmas over the holiday season.

Most emailed

Editorial

When I first started thinking about Free Software Magazine, I was feeling enthusiastic about the dream. I had Dave, Gianluca, and Alan willing to help me, I had established members of the free software community willing to help me out, I had writers volunteering their time and energy for free, and I had a generous offer from OpenHosting for servers, all before I'd proved myself. There was a sense of excitement in the air, and I thought maybe, just maybe, I could make this work.

Free Software Magazine uses Apollo project management software and CRM for its everyday activities!