Home arrow PHP arrow Moving Logic Into the Database
PHP

Moving Logic Into the Database


In this article Tim shows us how moving logic from our code into our DB can make life much easier and improve data integrity, he demonstrates this on a Gantt chart (task list).

Author Info:
By: Tim Perdue
Rating: 5 stars5 stars5 stars5 stars5 stars / 2
January 16, 2003
TABLE OF CONTENTS:
  1. · Moving Logic Into the Database
  2. · Triggers and PostgreSQL
  3. · Triggers and PostgreSQL (cont'd)
  4. · Conclusion

print this article
SEARCH DEVARTICLES

Moving Logic Into the Database
(Page 1 of 4 )

As my programming skills have improved over the years, I find myself demanding more precise and guaranteed control over my data, simply inserting into the database and hoping for the best is not good enough anymore.

Using transactions and foreign keys are good first steps in ensuring data integrity, but with some of the more advanced databases, you can go further still and move programming logic into the database itself, stripping it from your PHP code.

I recently picked up development of GForge, an open source software development/project management tool. Part of what I wanted to do was create a first-class "Project Manager", similar to MS Project or similar tools which do Gantt charting, and I wanted to do it with PHP using a web interface.

In Gantt charting, you have a series of tasks, which can be constrained by prior tasks, as in the example below. Task B is dependent on the completion of Task A, and Task C is dependent on Task B.

Gantt Chart

That sounds easy enough, but what if a user attempts to enter a start date on Task B that is earlier than the end date of Task A? At the time you insert Task B, or update its entry in the database, you could have PHP logic that queries the database and checks the end date of task A. That's a couple lines of PHP.

But what if you need to delay Task A by a week? Now you need a recursive function in PHP which will go all the way down the line and delay Task B and then Task C by the proper amount and commit all the changes to the db. Suddenly, you are looking at a lot of queries and recursion in PHP and you've got a performance problem, especially if you have a high-traffic web application.
blog comments powered by Disqus
PHP ARTICLES

- Removing Singletons in PHP
- Singletons in PHP
- Implement Facebook Javascript SDK with PHP
- Making Usage Statistics in PHP
- Installing PHP under Windows: Further Config...
- File Version Management in PHP
- Statistical View of Data in a Clustered Bar ...
- Creating a Multi-File Upload Script in PHP
- Executing Microsoft SQL Server Stored Proced...
- Code 10x More Efficiently Using Data Access ...
- A Few Tips for Speeding Up PHP Code
- The Modular Web Page
- Quick E-Commerce with PHP and PayPal
- Regression Testing With JMeter
- Building an Iterator with PHP

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials