Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...

When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Storing Images In MySQL

Article Comments (31 total)

Displaying article comments 31 to 31 of 31
Richard@Home, 26 April 2006

Sorry, still don't agree. It's still a bad idea. By all means store the meta data about an image (with a field for storing the filename) in a database because that's what the users are going to be searching for. Let's have a look at your benefits one by one:

Referential Integrity

This is the only benefit as far as I can see, and its a pretty tenuous one at that. It's pretty trivial to right some code that checks periodically if an image in the database has gone missing.

Ease of Backup

As opposed to what? The regular backup you perform of your website/application anyway?

Saving of Inodes

Dubious to say the least. I've created image directories with hundreds of thousands of images in with no problems. In fact, storing the images as files is better because if you need to increase the space for the images you just add a new hard drive and symbolically link the new directory.

Easy Categorisation

Which is just as easy as storing a link to the file along with its meta data.

Central point of operations

No, because now your image editors have to add another step to the process. Instead of just opening up an image in an image editor, making a change and saving it, they now have to upload it too. With all the problems of browser time-outs to complicate things even further. Also, you have to go to the additional step of pulling the (by definition, large) binary data out of the database, squirting it into an output file with the right headers and then sending the file to the browser. That's one more database query that could bring a busy website to its knees.

Submit a Comment
Use the following form to submit a comment for this article. You can include any required code snippets, which we will format and highlight accordingly.

Note: Before your comment appears on PhpRiot, it must be manually approved. The email address field is optional. If you choose to include it, it will be displayed obfuscated to protect it from spammers.

In This Article

Article History

Apr 19, 9804
Initial article version
Jan 18, 2008
Updated listing 5 to not include non-existent conf.php