HomePHP Building Object-Oriented Database Interfaces in PHP: Working with Multiple Data Access Objects
Building Object-Oriented Database Interfaces in PHP: Working with Multiple Data Access Objects
In previous articles in this series, we examined the concept of database interfaces, and saw source code for a "DBIGenerator" class. Working with multiple DB interfaces permits the accomplishment of several operations on many tables at the same time. Alejandro Gervasio demonstrates the power of this concept, with examples.
Here we are again. Welcome to the third part of the series "Building Object-Oriented Database Interfaces in PHP." I'm pretty sure that you've been working for a while with the concept of database interfaces explained in my previous articles, playing around with the source code defined for the already familiar "DBIGenerator" class.
In order to offer a brief summary of what we've learned until now about database interfaces, let's quickly review some key concepts. Undoubtedly, the most critical issue is to understand the why of the existence of such a programming structure.
Through the previous articles, we've seen that at times it is much better to implement a set of classes that sit between the database logic and the PHP application logic. This establishes a single access point to the data, and creates an efficient structure (the classes themselves) to wrap up core DML statements into "packages" that perform one-row operations on database tables. Definitely, the advantages of working with these classes become more evident when used with multiple DB interfaces, because it's possible to accomplish several operations on many tables at the same time, by using each class tied to a database table.
Having this concept in mind, I've developed a class named "DBIGenerator," which takes care of generating the proper DB interface for a given database table, building a class that represents the structure of the table in a logical way. Indeed, the "DBIGenerator" class behaves as a real "database access object factory," returning a new object that allows you to work directly on tables, executing single-row DML statements.
At this point, I firmly believe that you properly understand the basic theory behind database interfaces. Thus, it's time to make another leap forward in the learning process.
Either you've been developing your own set of DB Interface classes or simply expect to see several examples about its possible uses in Web applications. In this third part I will hopefully offer a practical approximation, by showing some concrete cases where the real power of DB Interfaces is clearly demonstrated. Are you ready to work with database interfaces in PHP? Fine. Let's get started.