Home arrow Zend arrow Page 4 - Build Database Interfaces

Autonomous With a Single Purpose - Zend

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.

TABLE OF CONTENTS:
  1. Build Database Interfaces
  2. Replacement Example
  3. Lessen the Impact
  4. Autonomous
By: Zend
Rating: starstarstarstarstar / 10
January 04, 2004

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement


Design the DB interface for a single purpose. This purpose is usually creating, updating and deleting a row of data. DB interfaces should be as autonomous as possible because that makes it easier to use them as a group. It is easier to combine the operations of multiple interfaces when each interface has a well-defined set of operations. (See example below.)

Standardized Design
Large applications that have many database tables result in many DB interfaces. Standardizing the way database interfaces are built makes them a lot easier to work with and become familiar with. Use a standard naming scheme, layout and implementation to simplify using multiple interfaces together.

Putting the Pieces Together
A single DB Interface is fairly limited in its usefulness. DB interfaces become very useful when their functionality is grouped together to perform a real task. Here is an example in which multiple database interfaces are combined to complete a new message posting on a forum:


<?php 
/* Notes: 
   $db    - instance of ADOdb connection object. 
   $user  - instance of the User DB Interface 
   $topic - instance of the Topic DB Interface 
*/ 

$db
->StartTrans(); 

// update the user's total # of posts 
$user->setNumPosts($user->getNumPosts() + 1); 
$user->submit($db); 
// update the topics # of messages 
$topic->setNumMessages($topic->getNumMessage() + 1); 
$topic->submit($db); 
// create the new message 
$message = new Message(); 
$message->setTopicID($topic->getTopicID()); 
$message->setTopic($_POST['userTopic']); 
$message->setMessage($_POST['message']); 
$message->setPoster($user->getUserID()); 
$message->submit($db); 
$db->CompleteTrans(); 
? > 

Conclusion
This article provided an introduction to using the DB interface design model for creating applications. As PHP applications become increasingly complex, they inevitably become more difficult to manage. Database interfaces provide a mechanism and a methodology for building more manageable applications faster and easier.



     
     
    >>> More Zend Articles          >>> More By Zend
     

    blog comments powered by Disqus
    escort Bursa Bursa escort Antalya eskort
       

    ZEND ARTICLES

    - Taking the Zend Certified PHP Engineer Exam:...
    - Quick Introduction to PHP 5
    - PHP SOAP Extension
    - Improving Performance
    - PDFs with PHP part 2
    - PDFs with PHP part 1
    - PHP at Lycos
    - Build Database Interfaces

    Developer Shed Affiliates

     


    Dev Shed Tutorial Topics: