0

Say I have a MySQL database structured like this:

id    name    png
1     Bob     img1
2     Jim     img2
.      .       .
.      .       .
.      .       .

where the png column store images as the BLOB datatype.

What I would like to do is loop through the database and print out all of the contents in the "name" field on a page where each name link provides a link to the respective image. Any feedback would be most helpful.

1 Answer 1

1

If the images are only saved as a BLOB in the database, you'll have to write a second script that fetches an image from the database and sends it to the client. You can then output links to this script (with a GET parameter so the correct image is displayed).

If the images are very small, I think you could also do it with the data URI scheme (you'd have to output the BLOB content of every image encoded as base64 inside the href of the link).

Sign up to request clarification or add additional context in comments.

2 Comments

Or you could just save the images in the database as base64 =)
@RobinJ: base64 has about 33% overhead compared to the original data, so it will take up a lot of storage space unnecessarily. Also, a rule of thumb is to always store data in databases in their most pure and natural form, in this case the binary representation of the image file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.