An introduction to Service Data Objects for PHP

by damonp on August 4, 2005

This is the way programming should be done. Unfortunately, in the real world few have time to build apps this way. Starting from scratch maybe, but working on code day to day especially picking up from another coder?

IBM Developerworks – An introduction to Service Data Objects for PHP

The thing I do use in everyday coding are data access functions.

<?php
function get_customer_record($id, $format='detail') {
    global $dbh;

    $dbh->Query("SELECT * FROM customers cust, address addr
            WHERE customer_id = '$id'
            AND cust.id = addr.customer_id"
);
   
    if($dbh->NumRows < 1)   return false;
    $customer = $dbh->FetchObject();
   
    switch($format) {
        default:
        case('db'):
            //do nothing just return customer object
            break;
           
        case('list'):
        case('detail'):
            format_customer_record($id, $format);
            break;
    }
   
    return $customer;

}

function format_customer_record($customer, $format='detail')    {

    switch($format) {
        case('detail'):
            //print out entire record
            break;
           
        case('list'):
            //print out minimal record for row listing
            break;
    }

    return true;
}
?>

Starting with these simple functions, you have access to the data and output mechanisms that can easily grow as your application design needs do. You can add new case statements to the formatting for use of the data in different ways or get the raw data and manipulate it inline for single use routines.

Popularity: 1% [?]

{ 2 comments… read them below or add one }

SIFE September 29, 2009 at 7:07 am

Salamo Alikom
some IBM tutorials required a valid login but when i login the tutorial still not displayed ,why ?

Reply

damonp September 29, 2009 at 8:38 am

I have no association with IBM. The tutorials were posted there back in 2004-2005. Try contacting someone there if you need access to the tutorials. They may have changed their link structure or removed the tutorials.

Reply

Leave a Comment

Previous post:

Next post: