SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Working on it... Contrid's Avatar
    Join Date
    Apr 2006
    Location
    Online
    Posts
    955
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    File data in database?

    Hi there guys,

    I read this PHP article just now and saw something that made me wonder/ponder. He was doing file uploads and inserting the full data of the file directly into the database.

    I know this is possible, but I have NEVER tried it. When I started out with PHP, it was said to me that this should preferably not be done since it slows an application down. I've always just worked with saving file into a directory and then using it from there.

    What are you opinions about saving file data directly into a database? Meaning the entire content of a file.
    And so I got lost in code...completely asphyxiated by it...

    Premium WordPress plugins - Tribulant Software

  2. #2
    An average geek earl-grey's Avatar
    Join Date
    Mar 2005
    Location
    Ukraine
    Posts
    1,403
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When storing files in database, DBMS will guarant consistency of your data (in case you use ACID-compliant database); in case of file system, you have to do it yourself.

    Check out this thread for some performance benchmarks.

  3. #3
    Working on it... Contrid's Avatar
    Join Date
    Apr 2006
    Location
    Online
    Posts
    955
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by earl-grey View Post
    When storing files in database, DBMS will guarant consistency of your data (in case you use ACID-compliant database); in case of file system, you have to do it yourself.

    Check out this thread for some performance benchmarks.
    Thanks for the link.
    I just quickly scanned over it and looked at the benchmarks.
    Will go through it thoroughly later on. Read the comments, etc...

    But from what I understand, my assumption was correct. The php/blob/mysql solution is indeed much slower than the php/apache solution. Not only the speed, but I'm sure that storing file data directly in the database will make system resources shoot up.
    And so I got lost in code...completely asphyxiated by it...

    Premium WordPress plugins - Tribulant Software

  4. #4
    SitePoint Zealot
    Join Date
    Jun 2007
    Posts
    150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Database might be more suitable if it's dedicated to the task and there are millions of *small* files.

    It's benefit comes from the tablespace being one continuous large file, instead of millions of smaller files which will kill file system throughput.

  5. #5
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When i initially was supposing to upload the images for some article system in my site, i just looked for some search engine and found this article in zend:
    http://www.zend.com/zend/trick/tricks-sept-2001.php

    And went thoroughly with the article. I saw a simple comparison between different types of image storing and loading methods and came up with the decision not to store the image data in the database blob field but store it as file system.

    Although someone might say there are some advantages on using mysql for storing images, but because of time file system (storing the files in the folders) will be the best way as i know so far.

    Lets hear some experts' view too.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  6. #6
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    The File System is the perfect place to store files because it is what it was designed to do and it does a very good job at that. A Relational Database was not meant to become a file system, yes it can hold files in there entirely but to manipulate them you have to pull them from the DB extensive overhead if its a large file.

    So I always use the File System to store files it is just logical. ^.^
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.



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
  •