sql database with pictures | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

sql database with pictures

hello, So I am trying to make a database that will contain a picture of a question, and then 4 pictures of options from which the user will pick one and the system will confirm if it is right or not. but I can't figure out how can I make a database like that. Anyone can offer some help?

22nd Sep 2022, 5:43 PM
Karan
Karan - avatar
3 Answers
+ 3
I think you can store the small images in a SQL table but it is not a good idea Instead create two tables , one will contain the "question" and other will have "options" and then link the "option" table using FOREIGN KEY ... For displaying them, use HTML. there are several benefits of this approach: a) You database size will be small which can save you money in production environment b) Faster loading of content(question and answer on your website) as the data you are fetching from database is small text as compared to images (which will be stored in binary) ------ Note: If you want to go your way, then I would like to pass this to others because I don't know how to store images(haven't tried just read this somewhere)
22nd Sep 2022, 6:44 PM
Sandeep
Sandeep - avatar
+ 3
Pictures can be stored in a SQL database in a data type known as Binary Large OBject, a.k.a. BLOB. I have programming experience storing and retrieving images this way for small icons and thumbnails as well as large images in enterprise management systems. It works well, but... few are familiar with BLOBs, the DB file grows enormous and so do backups, and it is not easily modified. I also programmed in several document management systems that stored only links to disk files. It works well, but... it is easily corrupted due to its flexibility (out of date links, image files get overwritten with wrong image). Overall, I prefer to use links to files on the disk. It is easier to troubleshoot and maintain link strings and disk files than to work with BLOBs. Though if you need to hide your question images from easy access, then BLOBs are good for that. Search for sample code and it will get you started. It is fairly easy to do once you establish the technique in your code. I no longer have examples of my own.
23rd Sep 2022, 12:31 AM
Brian
Brian - avatar
+ 2
A database does not store files and pictures directly but links to them. You can save a link to a URL if you are sure that the picture will not be deleted or save the picture on your application's server in a folder open to the public.
22nd Sep 2022, 6:39 PM
Roland
Roland - avatar