Re: PHP MySQL object question
- From: Jerry Stuckle <jstucklex@xxxxxxxxxxxxx>
- Date: Tue, 16 Sep 2008 17:32:01 -0400
William Gill wrote:
Jerry Stuckle wrote:That's one way to do it, and I use it quite a bit for low level operations on the database. In more complicated applications I layer a business object on top of the database objects.Not sure what you mean by "business object?"
Business objects are another OO layer on top of the database. They server to further decouple the application code from the data storage.
For instance, a business object may get information from several different tables, and when you update the data in the business object, it updates the underlying tables.
Since I am only dealing with one composite record at a time (editing) I was planning to store the original field data for before and after comparison to determine when and where updates are needed. (12 - 20 fields, from 4 or 5 tables) I could do it as separate session variables, but since each table record will have an associated object, why not just store them that way? Or are you suggesting save the id in a session variable, then re-select the db record and compare fields (with incoming data) to see which need updating?
Don't try to store large objects in your session, though. Better to store id's in the session rather than the entire object.
Just store the id and later just update the data. MySQL is smart enough not to update data which doesn't need to be changed. Or, if you don't have all of the data in the object, reselect the row, update the object then update the database. Unless your system is heavily used, chances are the original row will still be in the database's cache and retrieval will be very quick.
Of course, this is assuming no one else will be changing the data in the meantime. If they are, you have to save the old data (the session would work) and the second time around, fetch the data again. Compare the saved data with that in the object; if there is a difference you need to determine if it's important or not (i.e. if someone else updated column 'a' and you're updating column 'b', it's probably not a problem).
But just beware that when you save the object to the $_SESSION array, PHP has to serialize it, then unserialize it later. This can be a bit of overhead. And it can affect performance if your system is busy.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================
.
- Follow-Ups:
- Re: PHP MySQL object question
- From: William Gill
- Re: PHP MySQL object question
- References:
- PHP MySQL object question
- From: William Gill
- Re: PHP MySQL object question
- From: Jerry Stuckle
- Re: PHP MySQL object question
- From: William Gill
- PHP MySQL object question
- Prev by Date: Re: Why does my class require the public accessor for my member?
- Next by Date: Re: Mimicking a global variable
- Previous by thread: Re: PHP MySQL object question
- Next by thread: Re: PHP MySQL object question
- Index(es):
Relevant Pages
|