#1
  1. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,687
    Rep Power
    171

    UPDATE db or find a way to clear cache?


    Hi;

    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?

    Thanks
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    189
    Rep Power
    0
    My $.02.

    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!
  4. #3
  5. Wiser? Not exactly.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    5,958
    Rep Power
    4035
    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
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Dec 2004
    Posts
    3,016
    Rep Power
    376
    also requirements may change so it is better to plan for this.

    Comments on this post

    • Jacques1 agrees

IMN logo majestic logo threadwatch logo seochat tools logo