storing images in the database

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

storing images in the database

Post by GeXus »

I'm sure this has been discussed a lot, I see alot of advantages to storing images in the database as a blob or longblob.. however I'm wondering how doing this would stack up on a site like flickr or myspace... vs. on the disk...

Does anyone have any insight as to whether this would be a good idea or not, also, when storing images in a db, can people save as on the images or would it just be a php file.. like img.php?id=5, is it posible to have it be an actual image xxx.jpg, etc.


Thanks!!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Re: storing images in the database

Post by feyd »

GeXus wrote:I'm sure this has been discussed a lot
Yes, it has been discussed a lot.
GeXus wrote:I see alot of advantages to storing images in the database as a blob or longblob
I see very very few advantages. Advantages that are far outweighed by the disadvantages in fact.
GeXus wrote:can people save as on the images or would it just be a php file..
Done right, the browser shouldn't notice a difference.
GeXus wrote:is it posible to have it be an actual image xxx.jpg, etc.
Yes.
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Re: storing images in the database

Post by GeXus »

feyd wrote:
GeXus wrote:I'm sure this has been discussed a lot
Yes, it has been discussed a lot.
GeXus wrote:I see alot of advantages to storing images in the database as a blob or longblob
I see very very few advantages. Advantages that are far outweighed by the disadvantages in fact.
GeXus wrote:can people save as on the images or would it just be a php file..
Done right, the browser shouldn't notice a difference.
GeXus wrote:is it posible to have it be an actual image xxx.jpg, etc.
Yes.

Well, I guess the advantages that I see are that all data will be stored in a central location, easy for backup, etc.. (not that its exactly hard to copy files)... it just seems a lot more organized.

My understanding is that while in a DB it will use resources, the same is true when doing disk writes all day long. you disagree?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

With a database it will use nearly, if not, twice as many resources and system performance will suffer.

Why twice as many? When you request an image the database has to load it into memory, then php has to copy that memory into its memory.

Why will system performance suffer? You will need separate requests to the image display script for every image. PHP will have to load and run each of those requests separately too.
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Post by GeXus »

Awsome, well that makes the decision easy.. thanks!
Post Reply