-1

I am trying to store the URL of an image into a table in database. How do I do it and what data type is recommended. I tried other solutions provided on the internet but none worked for me somehow. OR... is it better if I just store the actual image itself? I appreciate your help.

Shadow
  • 33,525
  • 10
  • 51
  • 64
  • *How do I do it* Using INSERT or UPDATE query (depends by the structure and logic). *what data type is recommended* VARCHAR with proper length or some TEXT type. *is it better if I just store the actual image itself?* I doubt. – Akina Nov 12 '20 at 11:03
  • hi @Akina, if i want to store the path or location of an image (from my local folder) in the database in MySQL, is VARCHAR still the recommended data type? – user14489561 Nov 12 '20 at 11:59
  • Depends on the operations with the table. If this is only INSERT and SELECT then VARCHAR is safe else I'd prefer TEXT. – Akina Nov 12 '20 at 12:01
  • AFAIK shortcut is (binary) file whereas a path is a text string... – Akina Nov 12 '20 at 12:11
  • I would be really interested what suggestions you found on the Internet that did not work for storing URLs in your database! – Shadow Nov 12 '20 at 13:21

1 Answers1

0

You can store the actual image itself into the DB. But is not good approach because you will overload the DB. So it is not optimal.

From the other hand, you can store the images into some folder in your system and save in the DB the address. So in this case, you won't depend in 3rd parties for the availability of the image. This would be the most optimal.

If you want to keep in the DB the URL, VARCHAR type would do the job.

vsergi
  • 705
  • 1
  • 6
  • 16
  • hi @vsergi, could you elaborate on how to store the images in the folder and saving the location of the images in database table? may I know what is the recommended data type for this case? – user14489561 Nov 12 '20 at 11:58
  • This matter has been discussed more than once. You can see brief example in this post [how-do-i-store-the-location-of-an-image-in-a-database](https://stackoverflow.com/questions/4444442/how-do-i-store-the-location-of-an-image-in-a-database) – vsergi Nov 12 '20 at 12:10