I [I]think
I know it depends on the usage, but i wanted other people’s opinions on when to use PHP to process/filter/sort data and when to use the database.
Example: I have say 30-50 ‘objects’ each of the same type. They are each stored in the database and most of their properties are assigned to specific fields. As there are so few objects, my first reaction is to just pull them all out the database and do any searching/filtering in PHP to get the ones you want. That way, if elsewhere in the code you want the same lot of objects but perhaps ordered differently or only want ones on specific criteria, then there’s no need for another trip to the database because they are all already there.
For such a small sample of data i’m guessing storing them all in PHP is the best way. But at what point do you draw the line? What if out of all those objects you end up only using one of them – isn’t that a waste of memory? Even if you do use more than one, but then later want to re-order them and retrieve specific ones, then is it really that bad to do another trip to the database? Sorting and filtering data is after all what databases are designed for…