|
Posted by Erwin Moller on 08/14/07 07:57
larry@portcommodore.com wrote:
> I am working on a DB for family data, and in this application the data
> spans variable amount of rows in multiple tables (one for the adults
> data, one for "family", one for the kids, another for employment
> schedule, and another for businesses, etc.). I was thinking on
> selecting the entire family (IDs of all the related records) and
> storing them in a session array for easy access (from script to
> script) as I edit the data, but am wondering if there is a better way;
> what other methods do any of you guys have have?
>
> Am I correct in thinking this could be contained in a class? (I kinda
> get classes but not all the way yet) And if a class is a good thing
> - how is it persistent from script to script?
>
Hi,
Putting the data in $_SESSION could make sense, and it could very well not.
It depends on how big the structure (resultset) is you retrieve from the
database.
Sessiondata is saved to disk from page to page to make it persistent.
So if you session is 2 megabyte big, this will slow down your app a lot,
because of the saving and loading of such a big file.
(But also doing such a query every time on each page will probably make
your application slow.)
The bottomline is that it is hard to predict.
Personally I like to keep my sessions small, and make my queries smart.
About putting things in a class: That will not help you. Using objects
is a way of programming, not a way of optimizing your application
(speedwise, but it can increase the readability/structure of your code
of course).
My advise: Put things in a query that are really handy to have around
(such as userid, name, rights, etc) and leave the big amounts of data in
the database. A well structured database is VERY fast.
If you are unsure you can always profile the 2 approaches.
Simply store the microtime at the beginning of the script, and get it at
the end, and spit out the difference. Try this for Session-approach and
db-queries.
Remember that is the server is under heavy load, things might change a lot.
Hope that helps.
Regards,
Erwin Moller
[Back to original message]
|