-1

In my app I let users upload up to 5 images eg

vsdfjdifnd.jpg 
gfsffjdifnb.jpg 
asefjdidgd.jpg 
afdffjdifnd.jpg 
xcdfjdifnd.jpg

Should I store the image names one by one or as an array in my MySQL DB?

Right now I have a table called images that looks like this:

id - (PK) 
i_u_id - (FK) points to primary key in Users table 
image_name - (String) that holds the image name 'something.jpg'

It feels that my DB gets filled fast, so I was wondering I should store the image names as a array instead?

Kiow
  • 870
  • 4
  • 18
  • 32
  • 1
    Whatever are you worrying about here? How many images are you going to have to store? A billion? Don't worry about it. Hard drives hold, *at minimum*, 200GB. You'll run out of disk space for images before you "fill up" this table. – tadman Apr 11 '17 at 00:10
  • It's also worth making an effort to keep your column names coherent and meaningful. `image_name` is pretty good. `i_u_id` is opaque and meaingless. `user_id` might be a lot better. – tadman Apr 11 '17 at 00:11
  • See [Is storing a delimited list in a database column really that bad?](https://stackoverflow.com/questions/3653462/is-storing-a-delimited-list-in-a-database-column-really-that-bad/3653574#3653574) – Bill Karwin Apr 11 '17 at 00:50
  • 1
    *I was wondering I should store the image names as a array instead* **No, you should not** – apokryfos Apr 11 '17 at 08:37

1 Answers1

2

In this case it's smarter to store one by one, simply because otherwise once you want to remove or edit one of the image entries, youll have to parse the array, splice or edit the single image and then put it all back together and store the new array.

Also mysql can handle millions of entries just fine ;)

Manuel Otto
  • 6,410
  • 1
  • 18
  • 25