SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2002
    Location
    see above
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    storing images in a MySQL db

    what are the rules or a good tutorial on how to insert images into a MySQL db.

  2. #2
    SitePoint Addict EvilDoppler's Avatar
    Join Date
    Dec 2001
    Location
    Perth, Australia
    Posts
    217
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Talking Easy enough

    First and foremost rule EVER : do NOT insert the image into the database.

    Insert the filename and path instead. so much smarter and safer.

    cheers n' ears
    * Due to the last tax raise our prices has risen
    * - answers w/o thought $1 - answers w/ thought $3
    * - correct answers $10
    * - Dumb stares are still free

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2002
    Location
    see above
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh joy! thank you, so is that the same for mp3/video files as well? also does it have to be the complete url for a hosted site?

  4. #4
    SitePoint Evangelist thewitt's Avatar
    Join Date
    Apr 2001
    Posts
    468
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually, there may be very good reasons to store images in the database.

    Data integrity is one of them. If your images are related to other data in the database, and they need to be restored together from backups, it is often prudent to store these together in a database rather than trying to sync database restores with file system restores.

    You may also have much better performance with small images coming from the database (tens of thousands of thumbnails for instance) than you would with the file system overhead for each of these images. There is absolutely no reason not to store a 10k thumbnail image in the database rather than store a filename.

    Row caching may also make retreival of images from the database much more efficient than going to the file system.

    I would never say never store your images in the database, but you should review the architecture of the application, data retention and restoration procedures, and make an educated decision.

    -t
    myOstrich Internet
    OpenSRS Domain Registration, Digital Certificates
    Website Design, Hosted Email and now Blogware!

  5. #5
    Non-Member
    Join Date
    Jun 2001
    Location
    Rome,GA
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    say for example I have 10'000 images or better 50'000.
    How they supposed to be store on file system ?
    Can one folder holds that many?
    Or my script should take care of creating new folders when current one got its maximum?

  6. #6
    SitePoint Addict EvilDoppler's Avatar
    Join Date
    Dec 2001
    Location
    Perth, Australia
    Posts
    217
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by thewitt
    Actually, there may be very good reasons to store images in the database.

    Data integrity is one of them. If your images are related to other data in the database, and they need to be restored together from backups, it is often prudent to store these together in a database rather than trying to sync database restores with file system restores.

    You may also have much better performance with small images coming from the database (tens of thousands of thumbnails for instance) than you would with the file system overhead for each of these images. There is absolutely no reason not to store a 10k thumbnail image in the database rather than store a filename.

    Row caching may also make retreival of images from the database much more efficient than going to the file system.

    I would never say never store your images in the database, but you should review the architecture of the application, data retention and restoration procedures, and make an educated decision.

    -t
    I guess you could say that you have a point, though taking into consideration that my advice was based on a personal opinion I still am rather against the idea of storing 10.000 thumbnails in a database. The sheer size of the database would eventually be phenomenal. Also, from a rather paranoid point of view, keeping all your eggs in one basket has never been one of my idea of safe and sound application development. As I say, never trust a computer to do exactly what you want it to do. So in case of restoration procedures on a database with 10.000 thumbnails or that of a localized file/folder system I'd say that should something go wrong, why loose it all. Besides, a well thought/planned file/folder system works just as great for administration purposes as that of a database with a massive data load.

    Dunno, i'd still NEVER do it - but hey, to each their own fancy.
    * Due to the last tax raise our prices has risen
    * - answers w/o thought $1 - answers w/ thought $3
    * - correct answers $10
    * - Dumb stares are still free

  7. #7
    SitePoint Evangelist cyngon's Avatar
    Join Date
    Aug 2001
    Location
    Livonia, MI, USA
    Posts
    513
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well if you are intrested in storing images directly in a MySQL database using PHP, this tutorial should teach you everything you need to know:

    http://www.planet-source-code.com/vb...d=388&lngWId=8

  8. #8
    Non-Member
    Join Date
    Jun 2001
    Location
    Rome,GA
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmm... guys...there is something strange going on

    everybody agrees that it is not good thing to store images(full size) in database. The next question..i think logical one...how to store images in the folder? how many files can be stored in a folder....dont you think ? i need to "store" about 8'000 images and this "image archive" will grow... what should I do ? HELP !

  9. #9
    SitePoint Evangelist cyngon's Avatar
    Join Date
    Aug 2001
    Location
    Livonia, MI, USA
    Posts
    513
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think it really depends on the application.

    For example: Storing icons in a database would take up barely any room, so I think that would make sense in that case.

    But if your storing sizable images, it may not be a good solution.


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
  •