PHP
  Home arrow PHP arrow Abstracting Database Access Using Poly...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Actuate Whitepapers 
VeriSign Whitepapers 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Abstracting Database Access Using Polymorphism with Objects in PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 10
    2007-03-21

    Table of Contents:
  • Abstracting Database Access Using Polymorphism with Objects in PHP 5
  • What shouldn't be done when accessing distinct database systems
  • Using Polymorphism to create a database abstraction layer
  • Demonstrating the functionality of Polymorphism

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Abstracting Database Access Using Polymorphism with Objects in PHP 5


    (Page 1 of 4 )

    Polymorphism is an object-oriented programming concept that can be difficult to understand. This article, the first of a three-part series, walks you through the basics of Polymorphism so that you can make use of it in your own applications. The specific example in this article will show you how to use it with different database systems.

    Introduction

    Since the introduction of a highly improved object model in PHP 5, developing object-based applications with the latest version of this neat scripting language has been a greatly simplified process. This is naturally due to the implementation of diverse and powerful object-oriented features, such as visibility of class members, type hinting and exceptions, to name a few.

    However, while it should be admitted that the aforementioned improvements indeed facilitate working with classes and objects in a straightforward way, it's also true that building object-oriented applications can be a hard-to-master process. Most of the time this is because of inadequate knowledge of the main pillars of the object-oriented paradigm.

    In this case, you'll possibly know that I'm talking about Inheritance and Polymorphism. But what can be wrong with putting these theoretical concepts into practice, after all? Well, if you've been developing object-based programs for a while, then you've probably been consciously defining parent classes here and there. Logically you've also created numerous subclasses to perform concrete tasks.

    I have to admit that Inheritance is rather easy to grasp. It can be applied successfully with only a decent background in object-oriented programming. Nonetheless, there's a part of this schema that very often is completely omitted, or misused, in the best case. As you may have guessed, I'm speaking of Polymorphism, certainly a concept that presents some abstract aspects. Consequently, it's much harder to apply than Inheritance, at least in a real-world context.

    But take a deep breath and think twice. Actually, in the arena of object-based programming it isn't too difficult to understand how objects that belong to the same family can have different behaviors, even when they're using the same methods. And besides, there's an additional question that needs to be answered: how can this feature be used to create more efficient PHP applications?

    As you can see, questions come up very quickly when it comes to taking advantage of Polymorphism in PHP. This implies that the subject in question deserves a closer look. Therefore, keeping in mind the interest you might have in how to get the most out of polymorphic objects in PHP 5, in this three part series, I'm going to take a deeper look at some concrete situations where Polymorphism can assists in developing more robust and efficient object-based applications.

    More specifically speaking, in this first installment of the series, I'll be explaining how to implement Polymorphism to achieve a high level of abstraction when accessing different database systems. Subsequent articles will cover the use of polymorphic objects to build dynamic web documents and validate user-supplied input.

    So, having established the topics that I plan to treat in this group of articles, let's get started now!

    More PHP Articles
    More By Alejandro Gervasio


       · In this first article of the series, the concept of Polymorphism is used to create a...
       · I think you made a conceptual mistake in your exemple...You should not have...
       · Hello Fred,Thank you for your posting your comments. However, mi article doesn’t...
       · I've read almost all your articles regarding php and oop.This one is by far the...
       · I'm going to disagree with you both here. First, abstract classes also lead to...
       · Thank you for your compliments on my PHP article. I indeed appreciate them, and also...
       · Hello Pim,First off, thank you for posting your comments here, since I believe...
     

       

    PHP ARTICLES

    - Viewing and Editing Tasks for a Project Mana...
    - More on Private Methods with PHP 5 Member Vi...
    - Adding Tasks to a Project Management Applica...
    - Utilizing Private Methods with PHP 5 and Mem...
    - Making Changes in a Project Management Appli...
    - Defining Public and Protected Methods with M...
    - HTML for a Project Management Application
    - Using Subclasses and Accessors with Member V...
    - Implementing Internet Protocols with PHP
    - Project Management: The Application
    - Working with Private Properties to Protect P...
    - Protecting PHP 5 Class Data with Member Visi...
    - Setting Up a Web-based Image Hosting Service
    - Comparing Files and Databases with PHP Bench...
    - Setting Up a Web-Based Image Gallery





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway