December 22nd, 2013, 04:46 AM
UPDATE db or find a way to clear cache?
I often find myself in this situation, not sure what the best approach is.
Let's say we are dealing with "products". Each product can only have 1 photo.
Is it a better idea to
1 - Have a table product_photos and store the photo there or
2 - Save the photo with the same name for example $product_id.".jpg";
Solution 1 works better since there are no limitations (in case we decide to add photos) and there won't be cache issues on update.
Solution 2 is much less code and less database interaction.
Any comments on that?
December 22nd, 2013, 09:54 AM
I have always felt it to be better to store static images/documents/etc. outside of the db, with just the identifying criteria stored in a table with a reference to the specific file. That file can be stored along with all the others of the appl. in a single folder so that the table only has to reference the filename and not the path. Or you can stored different types of files in separate folders and let the appl determine from the filetype which path to follow.
This avoids the storage of the same image/doc/file twice - once as the source (somewhere!) and once in the table for usage. It also avoids having to do db retrievals and large query results for multi-record queries. And saves on db backup requirements!
December 22nd, 2013, 02:09 PM
As far as whether to just use the ID or a separate table for a photo list, I'd say the answer depends on whether you
a) Intend to (now or later) store any additional photo data
b) Intend to (now or later) allow multiple photos per product.
Basically, unless you are absolutely sure you'll only have one photo and need no other details for the photo, you are probably better off going with a second table with a list of photos and their details.
Either way you should store the actual photo data in a file on disk rather than in a database column.
Recycle your old CD's, don't just trash them
If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud
December 22nd, 2013, 08:32 PM
also requirements may change so it is better to plan for this.
Comments on this post