8/4/2005
An introduction to Service Data Objects for PHP
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.
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: 8%


