0

Possible Duplicate:
What is the best way to store a series of images in MySQL?

This is the first website that I built for a friend a few months ago: http://www.jpsinghphotography.co.uk

I want to rebuild it as my first PHP/MySQL project, but I had a couple of questions regarding how to structure the database.

1) Is it best to put the actual image files in the database using BLOB data types; or store the file names and use these to look up the images from another folder on the server?

2) I'm new to SQL and I'd initially imagined a seperate table for each gallery I want to create. In what ways is one table sorted by category better?

Thanks for any and all advice

Community
  • 1
  • 1
Sam Campsall
  • 128
  • 3
  • 14
  • Try searching this site, there are lot's of answers to your question. – Jacco Aug 18 '11 at 10:14
  • http://stackoverflow.com/questions/4774289/what-is-the-best-way-to-store-a-series-of-images-in-mysql/4774307#4774307 – Naveed Aug 18 '11 at 10:15
  • 1
    Regarding 2): Please have a look at relational database design and normalization, as seperate tables for each gallery is absolutely the wrong way to go. – Jacob Aug 18 '11 at 10:16
  • Sorry, didn't do a proper search around - schoolboy error :S Thanks for the responses. – Sam Campsall Aug 18 '11 at 10:24

2 Answers2

1

Welcome to stackoverflow.

  1. You can put image data in MySQL, but it's usually better to put them as files. That make them easier to cache and thumbnail, otherwise you have to do them yourself.

  2. One table sorted by category would allow you more flexibility in category names and make it easier to move images between categories as well as get information from multiple categories such as image count of each category.

Sheepy
  • 17,324
  • 4
  • 45
  • 69
0

I would stick to providing a reference ie. the file name in the MySQL table. Putting the images in the table as BLOBs would mean you're now maintaining two copies of your pics. If you're primary application is to store history, this makes sense, but otherwise, a simple reference to the original is probably better. A secondary issue may be storage space: you'd obviously be dealing with some very large tables if you BLOB the pictures. That may or may not be a problem. As others posted, creating multiple tables for each gallery is a definite no-no and against the whole philosophy of using a relational database. Simple add a column to the pictures table that holds the gallery id and make it part of the unique key. You may also want a separate gallery table too, to be more 'normalized' about it.

Pete855217
  • 1,570
  • 5
  • 23
  • 35
  • This makes sense - will potentially end up with 1000's of beefy images, which was my concern - file names it is then! – Sam Campsall Aug 18 '11 at 10:22