How many images can I save to a mysql blob field?

Asked

Viewed 379 times

3

I can record multiple images in one field blob?

Or I’ll have to create several fields? Imagem1, Imagem2 etc.... ?

I wanted to know if there is any way to do this without having to create several fields.

2 answers

4


A field blob stores a binary data set. You can store more than one image, turn both into a single data stream before. This has two immediate side effects: you need to know where one image starts and the other ends, and you necessarily have a larger file in that field.

This can be useful if you need to compress the data - multiple files in the same compressed package can result in a higher compression rate than multiple files in separate packages.

However, I believe that your problem is to save multiple images without knowing in advance how many images you will have to save for each record in the bank, right? In this case the ideal is to save the images in another table, with chave estrangeira where the record will go.

  • Then supposing that a news report has several images, how could I make the call of all the images?

  • @Márcioandré I suggest to open a more specific question for this. See also the answer of gmsantos.

  • @Márcioandré for your case we have a relation 1 -> N (a news may have many images). Why not normalize and create a separate table?

  • I’ve managed that level, thank you anyway.

3

Usually a column blob is made to store an image only.

If you need to store more than one image per entity, the solution to your problem would be to normalize the blob for a second external table:

Example:

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.