

David Wall, Morgan Kaufmann 2004, 278 Pages Pages
In this book author David Wall shows us how to create a PHP application based specifically on a multi-tier architecture and design. The question is: does it live up to the claims?
OVERVIEW
At this point in PHP’s dynamic evolution there is a new buzzword doing the rounds: "enterprise". It is becoming commonly accepted that PHP is a capable language choice as part of an enterprise solution; this book plays upon those thoughts and offers the readers a chance to witness the author build a complete PHP application with multi-tier architecture and scalability at its core, something of a dream for those of us who are at the level where they are progressing beyond the single server/application environment.
The book weighs in at ~270 pages with David Walls' friendly and personal writing style carrying you effortlessly through the 10 chapters on offer. This is an easy to read book, make no mistake about it and this is where it hits the first stumbling block – just who is the intended audience of this book? The book itself claims it is for PHP developers who are ready to move onto the next level, or for seasoned developers from other languages such as C++ or Visual Basic who are looking to move into multi-tier design with PHP. The problem is that the book isn’t actually authored for current PHP developers at all and will benefit only the real beginners to the language. The "chapter skipping" syndrome will unfortunately kick in for the rest of us.
THE "SKIPPING CHAPTERS" SYNDROME
I am sure most readers will have encountered a situation where you have a brand new book in front of you about a subject you are already familiar with but wish to expand your knowledge further, and you end up flicking past the first few chapters to get to the real meat. For me personally these are usually chapters such as "how to install PHP / MySQL", or those that are merely singing the praises of a certain methodology. If you are even a slightly experienced PHP developer you will unfortunately find yourself skipping an awful lot of chapters of this book, until before you realize it you’ve hit the Index at the end.
The first chapter deals with an introduction to the subject of multi-tier software. It defines the basic concepts, splits up the different levels (persistence, accessor, logic and presentation), lists the advantages and disadvantages of the approach and ends with some questions and exercises. In the Preface we learnt that the book is going to use the Model-View-Controller (MVC) pattern approach to the software design and the introduction re-enforces this through its recommended levels and diagram. While it is true that the deep topic of patterns should be left to dedicated books on the subject I found it surprising that you are simply told "this is how we’re going to do it" without a single explanation of why it is the right choice or even a basic overview of how the pattern operates. The Introduction is useful but far too short being only seven pages in length, which is a crime as it is the most important part of this book in my mind. For PHP developers who are wanting or needing to make the transition to a multi-tier architecture you will learn very little beyond the fact that you are going to be using SOAP and that "it's a good thing".
So what about that chapter skipping then? You’ll find it soon enough once you hit Chapter 2. If you have written anything in PHP that uses objects you can effectively skip this chapter entirely. All you learn about are very basic topics such as "Declaring a Class" and "Adding a Constructor", the sorts of thing you probably already do every day. Even the "advanced aspects" part of the chapter only deals with topics such as using [] to allow a class to refer to itself, so on we skip. Chapter 3 covers the HTTP protocol giving examples of GET and POST requests, something you are almost certainly familiar with; if you are not, the likes of Chris Shifletts’ HTTP Developers Handbook offers a comprehensive coverage of the topic. The rest of the chapter deals with using form elements (select lists, radio buttons, checkboxes) and ends with coverage of cookies and sessions. Somewhat ironically for a book supposedly about a multi-tier and potentially multi-server environment, the session section doesn’t even mention the fact that sessions are (by default) stored locally and offers no solution for a server farm sharing the same session mechanism/storage.
GETIING SOAPy
It became obvious early on that the only solution to handling multi-server communications this book is going to show is via SOAP. While in the scope of this book it is a sensible choice, I was shocked that no other techniques were mentioned, not even in passing. Chapter 4 deals with explaining SOAP to us, specifically SOAP via HTTP and it does a good, if brief, job of covering requests and responses, although (surprisingly) neglecting to even mention WSDL. SOAP is a large and complex subject and the author appreciates this, directing us to several alternative books.
The biggest issue with this chapter is the section on implementing SOAP in PHP. It relies exclusively on the NuSOAP library by Dietrich Ayala and every single example and piece of code herein uses it. Whilst no opponent of Mr. Ayalas’ fine library and though the back cover of the book clearly touts the fact that PHP 5 is what has made the language "enterprise ready", the book neglects to use any of PHP5s SOAP functions. They are admittedly still "experimental", but a mention of them early on would have been useful, especially to developers who may be reading this book several months down the line when the extensions are stable. Also neglected is the PEAR SOAP library, which is equally strange as the PEAR DB library is used extensively further on in the book. Of course if you are familiar with SOAP (even only very slightly), this chapter will have offered nothing new and you will have skipped on already.
SO ARE WE FINALLY AT THE MEAT?
Chapter 5 has a promising title, it implies that we’re going to actually get down and dirty and build a multi-tier application in PHP. This is exciting stuff and is why we as developers would have bought the book in the first place. If it lives up to our expectations then we can forgive the author for the previous 55 pages. The application is a simple one – it takes two cities, looks up their coordinates, and returns the distance between them. The cities are held in a database (the persistence layer), the accessor layer contains the methods to get the cities and their latitudes/longtitudes, the business logic layer performs the calculations and the presentation layer displays the HTML, with the communications between each layer going via SOAP.The three pages dedicated to explaining this layer approach and the objective of each layer are the most useful of the chapter. It is the part which developers new to the technique presented will glean the most from.
The database layer description includes creating a MySQL table and populating it, indeed a whole page of nothing but 'insert' statements. The Accessor Layer includes the NuSOAP library, registers a function to it, and performs a basic SQL query via PEAR DB. The data is returned and we are shown how to format it to pass it through NuSOAP. The Business Logic Layer section tackles being both a SOAP client and a SOAP server, with functions for both activities and finally the Presentation Layer displays the results by embedding stacks of PHP code in-line with the HTML (yes Smarty fans, you read that right). By the end of the chapter you’ve got a working application talking via SOAP.
REPEAT AD NAUSEAM
It might not have been the most in-depth example possible, but at least we now have a solid working application that could quite happily be split across several servers on several networks if needs be. It is getting quite exciting, so hopefully we will learn something more in the coming chapters? Well, you’d hope so, but fundamentally this is where the book ends for most us. Chapter 6 is all about selecting which database server is right for you, talking about "First Normal Forms" and then no less than five pages worth of create statements for the coming application. The entire chapter is a write-off for anyone who has worked with a database before. Chapter 7 teaches us how to perform SELECT statements (I kid you not), moving on to inner and outer joins. Further on in this chapter we learn about which queries are going to be required by the main application of the book (called Currawong Accounting), a list is made which I thought was a useful exercise for application design, however we are then subjected to reading the author go through every single query and turn it into a function. There is literally page after page of this and while I can see the point of it, every single function performs the same task (on different data). If you’ve ever selected from, inserted to, updated or deleted from a MySQL table before, you will learn absolutely nothing here.
Chapter 8 is the Business Layer, which means we get to see every script created to access the previous functions as a SOAP client, only this time we get to see the output as HTML all of which is embedded into PHP echo statements, line after line of them. At this stage of the book we are into masses of PHP code, none of which does anything particularly impressive and most worrying of all, none of which does anything that we didn’t learn back in Chapter 5. Chapter 9 is the same again, this time being the end-user HTML in the form of the Presentation Layer. In fairness, the author does mention Smarty right at the start of this chapter and encourages us to use it, but then promptly ignores this advice. The HTML given is a mess, does not comply with any web standards (four tags in a row anyone?!) and is stacked full of PHP code and PHP security flaws – the entire array being extracted into the global variable scope for example, and not even via the PHP extract() function either, but from a foreach loop. To add insult to web standards injury he injects frames and JavaScript to the mix as well.
GET ME OUT OF HERE!
By the end of Chapter 9 there are only a handful of pages left of the book and they deal with obtaining information from other Web Services including a lengthy section of an XMethods.net currency exchange WSDL file, which is broken down and analyzed – something which should have been done back at the start of this book. The Afterword is nothing more than a list of “what would make my accounts program better?” with a vague promise that perhaps some of those ideas will be addressed in a further edition.
I simply cannot understand who this book is aimed at. No serious PHP developer would learn anything from the page after laborious page of barely adequate functions, invalid HTML and a "teaching granny to suck eggs" attitude to table design, objects and SQL. For developers who are brand new to PHP I can see this being more useful and yet it does not cover the core language well enough and ultimately it is not what the title of the book really promises. But for those who were really hoping for a solid grounding in multi-tier application design and implementation, you will be left feeling cheated out of your hard earned money. There is a large gap in the PHP book market for a title of this nature; sadly this one does not come close to filling it.


Open Source Web Development with LAMP
Derick Rethans
This book on LAMP is not primarily focused on PHP, actually quite a small part is devoted to PHP.It starts with a very brief explanation in …
MySQL Cookbook, Second Edition
Paul DuBois
A handy resource when you need quick solutions or techniques, this Cookbook addresses specific questions in using MySQL. You'll find dozens of short, focused pieces of …