PHP Oracle Web Development

I was recently given the opportunity to review a new book on the subject of PHP and Oracle databases. We use Oracle databases nearly exclusively at work, so this seemed like a good opportunity to me.

cover imagePHP Oracle Web Development” itself resembles many other technical references available for PHP, soft cover, approximately 375 pages, from Packt Publishing. The author is Yuli Vasiliev who has written several articles for the Oracle Technical Network. A quick look over the table of contents revealed a reasonable plan of attack: Why use Oracle with PHP, how to get things setup, how to connect and use the connection. Then it proceeded into some more detailed specific topics: transactions, security, caching, XML, web services and AJAX.

The “Why use Oracle” section covered the technical capabilities and advantages of the Oracle database well, but it also highlighted the complexity of setting up an Oracle database, which is probably one of the primary stumbling blocks for anyone who was already familiar with PHP/MySQL to try transitioning to using Oracle for a database. The book touched on the Zend Core for Oracle in this chapter, and a bit more in the appendices, but this just provides the Apache/PHP/PHP Oracle Client libraries, the user still has to get an instance of Oracle up and running, which can be a somewhat daunting challenge. So, while the chapter was not an Oracle sell job, you will get a reasonably accurate picture of what the setup will involve from reading it.

The next chapter covered PHP and Oracle Connection, covers your fundamental “How do I talk to the database?” questions. This chapter (and the rest of the book) uses the PHP native OCI8 functions, though the chapter does touch on database access and abstraction libraries like PEAR DB, ADOdb and PDO. Having written a book before, I can sympathize with the decisions an author is faced with, in this case either having completely portable code which will work “cut and paste” from every example, or by introducing some kind of a database access library to eliminate some of the more tedious and repetitive code, but introduce a new dependency for the subsequent example (either the selected code library, or a custom library written for the book). Coming from a production environment, I fall down on the side of putting a database access library in place which enhances developer productivity. On the other hand, it may just be a personal pet peeve of mine, as the examples in the book remind me of code from my database administrator who insists on using native OCI functions rather than the standard access library we use throughout the rest of our code base.

The chapter on Data Processing introduces the readers to concepts like stored procedures and triggers, certainly beneficial and potentially unfamiliar concepts for anyone migrating from a PHP/MySQL background to this RDBMS. The chapter on OOP presented some initial material on refactoring, some discussion of errors and exceptions, and an introduction to some standard libraries like PEAR.

Chapter 6 covered security, and introduced using the PEAR::Auth class in combination with some custom packages. Clearly any sort of a user based authentication is going to have to be persisted somewhere, and where better than your database? This chapter did a nice job of showing how to integrate third party code like PEAR::Auth into your application while storing the underlying details in Oracle. Sometimes the same word is used for different meanings in different technical domains, and this was highlighted for me in this chapter when the author discussed both database sessions (as they related to package state) and PHP sessions. There is an impedance mismatch between these two concepts, and sometimes you had to pause a bit to decided which context of these two “sessions” is being used.

Honestly, I have not personally “drank the XML kool-aid”, and I was therefore a bit dubious when I approached the chapter on XML. I was pleasantly surprised, the author covered significant Oracle functionality in the area of XML processing which I did not have experience with (including XSLT processing and using XMLType and XQuery to fetch the stored XML data). These promise to be powerful techniques if XML is a standard you are working with.

The chapter on AJAX was another one I approached with a bit of skepticism. It would seem to be just the kind of thing being included in order to be “100% buzz-word compliant”, after all what does client side JavaScript calls have to do with the database PHP happens to be accessing? The author did a good job of both showing relevant usage (parent-child relationship management, an area AJAX certainly can help with) and also integrated some useful Oracle code to build on the XML chapter and use XSLT to return pre-formatted HTML for use in your AJAX application. Overall this chapter was a good introduction to AJAX techniques.

In summary, this book targets the niche of Oracle used in conjunction with PHP. This combination is certain to increase with the addition of PHP to the standard Oracle application stack. The book was written with no assumption on the skill level of the reader with regards to PHP. It would clearly be an asset at an organization which already has Oracle deployed, and is now starting to dip into PHP. On the other hand, the bookshelves at book stores are loaded with introductory texts for PHP, and while this book serves an outstanding role Oracle specific resource, it is probably not the best introductory source for PHP overall. The two audiences I believe would benefit the most from this book are locations which have Oracle deployed and want to start using PHP, and programmers who are not familiar with the capabilities of Oracle who would like a well written introduction to the capabilities of the Oracle database.