PHP
  Home arrow PHP arrow Refactoring the MySQL Abstraction Class with the Active Record Pattern
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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

Refactoring the MySQL Abstraction Class with the Active Record Pattern
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 4
    2009-04-07


    Table of Contents:
  • Refactoring the MySQL Abstraction Class with the Active Record Pattern
  • Refactoring the MySQL sample class: modifying methods that perform CRUD operations
  • Completing the refactoring process of the MySQL abstraction class
  • Manipulating database records using the improved version of the MySQL class

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    Refactoring the MySQL Abstraction Class with the Active Record Pattern
    ( Page 1 of 4 )

    In this group of articles you’ll be provided with an approachable guide to building a database accessing class that will use the programming model imposed by the active record pattern for performing raw CRUD operations on a group of selected MySQL tables, and for fetching database records by using the WHERE, LIKE and LIMIT clauses as well. This is the sixth part of a seven-part series.

    Introduction

    When it comes to implementing the active record design pattern with PHP, in most cases data mapper objects are used to interact with a certain number of databases. Generally, these objects act like a single, unified interface that can be used to perform CRUD tasks (Create, Retrieve, Update, Delete) on mapped tables.

    This schema obviously permits you to achieve a high level of SQL abstraction, since executing the mentioned tasks against a selected database table doesn’t require directly writing any SQL statements. All the business logic is handled behind the scenes by the objects in question.

    However, it’s perfectly feasible to apply the active record pattern by using just a database accessing class, and still get an acceptable grade of SQL abstraction, particularly when it comes to inserting, updating and deleting records of a specific database table.

    Now, returning for a moment to the topics discussed in the last installment, I left off explaining how to build a simple MySQL abstraction class, which had the ability to fetch a predefined number of records from a sample “users” MySQL table by using a LIMIT clause. In this particular case, a concrete method within the class was responsible for performing this task, without the need to code explicitly any SQL statements from outside the class.

    As I stated in the end of the tutorial, however, some methods of this sample class implement redundant business logic, and as a consequence it’s necessary to refactor them to fix this issue in a quick and simple manner. Thus, in the next few lines I’ll be explaining how to accomplish this process progressively, and as always, accompanied by the corresponding code samples.

    Now, it’s time to start modifying the signature of this MySQL abstraction class to make it more efficient and compact. Let’s go!



     
     
    >>> More PHP Articles          >>> More By Alejandro Gervasio
     

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    Stay green...Green IT