This article is about using and building Database Interfaces (DB interfaces). DB interfaces make application development faster and easier. This is accomplished by relocating scattered DML (Insert, Update, Delete) statements into a single shared tool, the Class. A Class encapsulates data post processing, integrity, and security into a single tool that can be accessed throughout the application.
Another advantage to using a DB interface is that changes to the structure of the database have less of an impact on the application. Changing a single DB interface is far easier than finding and modifying code and embedded SQL throughout an entire application.
Creating a Database Interface There are a few general guidelines that you should follow when designing your database interface:
Use an object oriented approach and follow OOP principles.
Make the DB interface autonomous and with a single purpose.
Base the DB interface on a standardized design.
Use an Object-Oriented Approach A class should be used to create each DB interface you require. This class should be a logical (code) representation of a single database structure. The members of the class represent each column of a row. The methods of the class should perform the DML and DQL operations on the row. The example below illustrates how DDL and DQL operations are implemented through the load(), submit() and delete() methods.
<?php
class Client { var $clientID = 0; var $firstName = ''; var $lastName = ''; var $emailAddress = '';
function Client() {} function load(&$db,$clientID) { $DQL = 'SELECT clientID,firstName,lastName,emailAddress '. 'FROM client '. "WHERE clientID=$clientID";