2 Replies - 11744 Views - Last Post: 18 May 2011 - 07:32 PM

#1 agent_logic  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 38
  • Joined: 21-July 08

Best strategy to display multiple images related to an object

Posted 16 May 2011 - 01:38 PM


I am using the LAMP stack to develop a uni project. This has to do with a fictitious real estate company selling properties. Each property would consist of varying number of images associated with it. I am just wondering what would be the best strategy to store these images: in a MySQL BLOB or in the file system? I've been reading a few articles that discuss that BLOBs are a bad idea, especially if the number of images are going to be huge.

I've been thinking to get the file paths of the images while they are being uploaded, and then store those paths (probably comma separated, or should I go for multi-valued attributes?) in a column of the property table. Then, I'd get that column value, use the PHP split() function to get individual file paths and accordingly put them in <img> tags. What do you guys think? Is this tedious or is there a better way?

Thanks in advance.

Is This A Good Question/Topic? 0
  • +

Replies To: Best strategy to display multiple images related to an object

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon

Reputation: 10816
  • View blog
  • Posts: 40,317
  • Joined: 27-December 08

Re: Best strategy to display multiple images related to an object

Posted 18 May 2011 - 06:45 PM

I would use a linking table here to associate an object with an image. This makes it easier to add more images to a single object and query for specific images later, rather than dealing with excessive string manipulation.

object_id (PK, FK) | image_path (PK)

BLOBs aren't a good idea b/c they add a significant load to the database, slowing query time significantly. Strings take up a lot less space, so the load on the database is a lot less.
Was This Post Helpful? 1
  • +
  • -

#3 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3730
  • View blog
  • Posts: 6,017
  • Joined: 08-June 10

Re: Best strategy to display multiple images related to an object

Posted 18 May 2011 - 07:32 PM

Generally speaking, whenever you think the term "comma separated" or "serialized", or anything of the sort, when designing relational databases, you are likely doing something wrong. -- Let the database manage the data. It's what it does best.

The first, and most important, rule of relational database design: Only one piece of data per field.
When you start manually managing the data as serialized strings, you open yourself up to all sort of issue, like: data corruption and query difficulties. -- I mean, how would you have a query search for a single path when the database considers all your paths to be a single value? You'd have to use some heavy string manipulation for that, and that's a sure way to kill your performance.

Of course, we can argue endlessly about what does and does not qualify as "one piece of data", but in this case it's pretty safe to say that a single file path does qualify, but a string a comma separated file paths does not.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1