Review: Learning PHP Data Objects by Dennis Popel
Packt Publishing graciously provided me with a copy of this book to review.
PHP supports more than a dozen database setups, including the SQLite library bundled with PHP 5. That’s a lot of databases, and each one has its own connection syntax and server-specific functions.
So what happens when you want to be able to swap one database for another? You turn to an abstraction library, such as PDO.
In Learning PHP Data Objects, Dennis Popel takes you through the process of building an application using PDO with MySQL and SQLite.
Aimed squarely at PHP developers who are new to PDO, Popel covers how to make connections, handle errors, and use prepared statements with PDO. He also discusses transactions, MVC development, and the appropriateness of using PDO versus other abstraction libraries.
Where Learning PHP Data Objects shines, however is in its code examples. They are easy to follow, and Popel smartly alerts readers to potential gotchas in developing the sample application.
The book assumes an understanding of OOPHP — necessary because PDO is entirely object-oriented. To get the most out of it, you should be familiar with object-oriented principles and syntax. While Appendix A does give readers a quick overview of OOPHP, for a more thorough treatment, you’ll need to look elsewhere.
It’s a solid, though not quite perfect book. For example, Popel only sort-of mentions a potentially huge gotcha: when you may need to specify a unix_socket parameter in the connection string. It’s a problem I think would be common enough and confusing enough to discuss and demonstrate. I also think Popel could have been a bit clearer about when and why to use
Those are minor quibbles however, easily solved by consulting the documentation or doing a Google search. Overall, this book is nice introduction to the whys and hows of using PDO to develop database driven applications.
- Learning PHP Data Objects
- Packt Publishing
- September 2007
- ISBN number: 978-1-847192-66-0