Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-26-2011, 06:47 PM   PM User | #1
Keleth
Senior Coder

 
Join Date: Jun 2008
Location: New Jersey
Posts: 2,354
Thanks: 45
Thanked 247 Times in 244 Posts
Keleth is on a distinguished road
Pros/Cons to storing images in database?

I ran across an article today about how to store images in a database. I found it fascinating, and a very simple method of storing images that are uploaded.

I am wondering, as long as I do the proper sanity checks when inserting, what the pros/cons of images in a database are? Is this method used on professional sites? In what context? I'm guessing its not for stuff like backgrounds or design elements, as I take these images wouldn't be stored as temporary files?
Keleth is offline   Reply With Quote
Old 12-26-2011, 08:48 PM   PM User | #2
Apothem
Regular Coder

 
Apothem's Avatar
 
Join Date: Mar 2008
Posts: 380
Thanks: 36
Thanked 25 Times in 25 Posts
Apothem is an unknown quantity at this point
As far as I know from my small experience (though do remember that quality of pros/cons should outweigh the quantity):

Pros:
- Files are saved "forever"
- Can restrict access to the real file more easily
- You can, technically, check for duplicate files.
- You are not keeping the files on drive, so it can be faster to access for the server
- Less files on your server is considered "better" and more organized
- "one file for everything"

Cons:
- If site is up but database is not, file will be invalid (through "direct" linking)
- Some databases that cannot be reconfigured only allow blobs to be of a certain size limit (a few mb), therefore making it so that really large images cannot be stored (but can be separated)
- More data becomes stored in memory when loading file to (to a variable); similar to the problem above, very large images can slow down your server.
- Some files may be of different character encoding, and thus storing and/or retrieving files may corrupt the original file. I am not sure if this is real problem, but I think it was.

I personally do not store files on my database anymore because of the cons.
Apothem is offline   Reply With Quote
Old 12-26-2011, 10:14 PM   PM User | #3
Keleth
Senior Coder

 
Join Date: Jun 2008
Location: New Jersey
Posts: 2,354
Thanks: 45
Thanked 247 Times in 244 Posts
Keleth is on a distinguished road
Very interesting.

So far, I've only been considering using it for profile images, as I couldn't think of these its really applicable. But I've heard it discussed before and I don't yet see how its used in a professional site.

I have some ideas mind you... I recently made a site for a used car dealership, and they wanted the ability to upload multiple images of the vehicle. So I set it up that when the vehicle dataset was created, a folder was made under the ID in a folder for the images, and any uploaded images were moved there. It was a bit of a messy system. Having them upload to a DB would have been cleaner.

Any thoughts to other possible uses? Or is it really just an obscure technique, not oft used?
Keleth is offline   Reply With Quote
Old 12-26-2011, 10:35 PM   PM User | #4
Apothem
Regular Coder

 
Apothem's Avatar
 
Join Date: Mar 2008
Posts: 380
Thanks: 36
Thanked 25 Times in 25 Posts
Apothem is an unknown quantity at this point
I don't think it's obscure; its uses are as I have described in the Pros. It really just depends on how you want to store files. More over I don't think it's exactly correct to say that storing files in a database is cleaner because if you have a proper data structure to store file information and files, it can be just as clean (if not cleaner). Of course that does require more coding, and as a programmer myself I find it trivial to write more code when there is something already out there for me to use.

I cannot come up with many ideas of the uses of this, as my interaction with it was generally with file management systems. So if it has anything to do with managing files, storing files in a database can apply.
Apothem is offline   Reply With Quote
Old 12-27-2011, 01:19 AM   PM User | #5
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,248
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
One *HUGE* PRO for images in the DB: In a truly large system, the DB might be distributed across many servers. Or in even a fair-sized system that needs 100% up-time the DB might be replicated across multiple servers. With the images in the DB, then images are also distributed and/or replicated. You *can* set up file replication, but it's generally less well-supported than DB replication/distribution.

But if you are on a relatively small system, especially one where the DB server and the Web server are on the same machine, I don't see any pro's worth considering, really.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 12-29-2011, 01:49 PM   PM User | #6
ineedwebsite
New Coder

 
Join Date: Dec 2011
Location: Ukraine
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
ineedwebsite is an unknown quantity at this point
Pros. If images are stored as files it may cause you problems with server backups and overall server speed. For example when you try to archive files from control panel web gui or run a backup process, this operation will take longer time and most likely crash.

Therefore most of shared hosting plans have restrictions on the number of files that can be stored under an account.
ineedwebsite is offline   Reply With Quote
Old 12-29-2011, 05:46 PM   PM User | #7
Keleth
Senior Coder

 
Join Date: Jun 2008
Location: New Jersey
Posts: 2,354
Thanks: 45
Thanked 247 Times in 244 Posts
Keleth is on a distinguished road
Ah, ok, so probably not something I'm too interested in right now, but for larger projects, its a viable if not preferable alternate.
Keleth is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:37 PM.


Advertisement
Log in to turn off these ads.