0

Is that a good idea to save image data inside database?

I'm currently converting user's uploaded photos to DataURI using base64_encode. And save the result to MySql table with datatype "Longtext".

When I display, I select the value and put inside HTML IMG source like this <img src="<?php echo $photoColumnName; ?>" />.

It works fine when I tested on local machine but when it goes online, the page loads very slow.

Is it better to save the image inside folder?

Thanks.

Den
  • 369
  • 1
  • 4
  • 12
  • 2
    unless you *know* that storing images in your DB is better for your specific use case, you should stick to the file system. let the webserver handle caching and everything, it will greatly improve performance in your case. also - if you have to store them in your DB; use a blob-field, not text. – Franz Gleichmann Oct 20 '16 at 09:57
  • 1
    a good quality image have a large base64 value, So do not use it. – Kumar Oct 20 '16 at 09:58
  • That answered my question. Thank you guys. Philipp, Franz and Kumar. – Den Oct 20 '16 at 10:04

1 Answers1

0

As a practice please do not store blob or meaningless data in a RDBMS. These will increase your row size meaning you can store less rows in a page file. That means you have to read more page files in order to find few meaningful records. Every RDBMS the performance bottleneck is the disk I/O. Hence please do not compromise that for storing meaningless data. Best practice is to store the URI and retrieve the content when necessary.