PHPBuilder - Smart Architectures in PHP Page 5



RSS Twitter
Articles Application Architecture

Smart Architectures in PHP - Page 5

by: Tim Perdue
|
October 10, 2000

For simplicity's sake, this example will not be based on a perfect object model, as I'd have to explain the base classes and how the other objects extend those base objects. I think this example will still give you the general idea.
Example HTML Lib

<?php

//connect to database
require ("database.php");

//common utils like header/footer HTML
require ("html.php");

//data access library
require ("bug_data.php");

echo 
site_header("Page Title");

echo 
"<H4>Updating A Bug</H4>
    <P>"
;

if (
bug_data_update($field1,$field2,$field3)) {

    echo 
"<H3>Update Failed!</H3>";

} else {

    echo 
"<H3>Updated Bug Successfully</H3>";
    
//echo the global error string
    
echo $feedback;
}

echo 
site_footer();

?>
Example Data Access Lib

<?php
/**
 *
 *  controls access to updating a bug in the
 *  database. Validates data and checks security
 *  Returns true on success, false on failure
 *
 */

function bug_data_update ($field1,$field2,$field3) {
    
//global string to report back errors
    
global $feedback;

    
//$field1 and $field2 are required
    
if (!$field1 || !$field2) {
        
$feedback="Field 1 And Field 2 Are Required";
        return 
false;
    }

    
//make sure this user has permission to update
    
if (!user_isadmin()) {
        
$feedback="You Must Be An Admin To Update a Bug";
        return 
false;
    }

    
//now let's update the bug

    
$result=db_query("UPDATE bug ".
        
"SET field2='$field2',".
        
"field3='$field3' ".
        
"WHERE id='$field1'");

    
//now check your query for success/failure
    
if (!$result) {
        
//update failed
        
return false;
    } else {
        return 
true;
    }
}

?>

« Previous Page
1
|
2
|
3
|
4
|
5
|
6
Next Page »

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Tim Perdue

Comment:



Comment:

(Maximum characters: 1200). You have characters left.