SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Hybrid View

  1. #1
    SitePoint Wizard johnn's Avatar
    Join Date
    Mar 2001
    Location
    Southern California, USA
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Storing images in database or not?

    Hello,
    I would like to know should I store images in database, or should I store them in files and their filenames in database?

    Also when is it better to store binary data in a database?

    Thanks in advance,
    John
    Last edited by johnn; Nov 14, 2001 at 02:00.

  2. #2
    Yugo full of anvils bronze trophy hillsy's Avatar
    Join Date
    May 2001
    Location
    :noitacoL
    Posts
    1,859
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Mu personal preference is not to store binary files in a database unless I have to (from a technical or requirements point of view). But if you really need to, go right ahead

    Have a look @ this thread: http://www.sitepointforums.com/showt...threadid=39345

    also this one:

    http://www.sitepointforums.com/showt...threadid=38728
    that's me!
    Now A Pom. And a Plone Nut
    Broccoli Martinez Airpark

  3. #3
    Grumpy Mole Man Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,067
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'd say if you have the option to store images outside the database then do it - relational databases weren't designed for storing images, and although they can do it (BLOB fields etc) it causes all sorts of nasty headaches with performance / searches etc and is best avoided.

  4. #4
    SitePoint Wizard johnn's Avatar
    Join Date
    Mar 2001
    Location
    Southern California, USA
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So, it's not that good to store images in database. I just read a new article at Zend:
    http://www.zend.com/zend/trick/tricks-sept-2001.php

    According to the article and discussions there, there are pros and cons in both ways.

  5. #5
    Yugo full of anvils bronze trophy hillsy's Avatar
    Join Date
    May 2001
    Location
    :noitacoL
    Posts
    1,859
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    More cons than pros it seems. But as always, it comes back to the best tool for the job. If you have a very specific reason why you need to store the image in a database then do it (the author cites distributing it over several servers as a reason). But even then there are alternatives - I've used network filesystems to do just that.

    And all that code just to load an image?
    that's me!
    Now A Pom. And a Plone Nut
    Broccoli Martinez Airpark

  6. #6
    SitePoint Evangelist thewitt's Avatar
    Join Date
    Apr 2001
    Posts
    468
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One of the classic "right" applications where images should be stored in the database is when the filesystem overhead outweighs the database query overhead.

    We built an image database for icons and "smilies" and other very small images. This site gets about 2,000,000 requests a day for these images. The database delivers them without blinking. The file system version was so overloaded that the consultant's answer to the problem was a $250,000 storage device to put a couple dozen spindles under the I/O.

    We told the customer that we would do the project for free if performance did not improve to a satisfactory level (one of my designers was absolutely certain the database design would outperform the filesystem version). We were paid $50k for 2 weeks work and the customer was thrilled with the results.

    It's all about what tools are appropriate for the application at hand.

    -t

  7. #7
    Database Jedi MattR's Avatar
    Join Date
    Jan 2001
    Location
    buried in the database shell (Washington, DC)
    Posts
    1,107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    TheWitt makes a very good point -- most RDBMS' have very advanced caching mechanisims and chances are will store the images cached in RAM (so it is very, very fast to pull out). Most web servers that I know of are pretty stupid when it comes to serving things like static HTML and dumb images -- it will continually pull them from disk even though they do not change.

    Hopefully if Apache grows up (multithreaded, caching like that) those problems will be a part of the past. Until then, give your DB lots of RAM and you should be fine.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •