ozmnow's avatar

Store image names one by one or as array in mysql db?

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?

0 likes
1 reply
Indemnity83's avatar
Level 22

What's wrong with filling a database; that's what it's for!

Unless there is something unique about each of the 5 images (ie, the first is always the user's profile picture, the second is their car, etc...) then I think the way you have it implemented now where a User hasMany Image and images are on their own table.

You just have to implement a little logic to maintain the 5-image limit is all (count $user->images as a validation before storing)

Please or to participate in this conversation.