PhpRiot
Download This Article
Download this article in PDF format with all listings and files.

Price: $5.00 AUD
(Approx. $4.10 USD)

More information
Related Books
PHP and MySQL Web Development (4th Edition) (Developer's Library)

PHP and MySQL Web Development (4th Edition) (Developer's Library)

PHP and MySQL are popular open-source technologies that are ideal for quickly developing...

PHP 6 and MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide

PHP 6 and MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide

It hasn't taken Web developers long to discover that when it comes to creating dynamic,...
Browse Articles
Ajax (4), APC (1), CAPTCHA (1), CSS (3), Debugging (1), File Upload (1), Google (3), Google Maps (2), JavaScript (12), JSON (2), MVC (1), MySQL (7), onbeforeunload (1), OOP (1), PHP (28), PhpDoc (1), PostgreSQL (6), Prototype (11), Reflection (1), RFC 1867 (1), Robots (1), Scriptaculous (1), SEO (1), Sessions (1), SimpleXML (1), Smarty (5), SOAP (1), SPL (1), Templates (2), W3C (1), XHTML (1), Zend Framework (1), Zend_Search_Lucene (1)

PhpRiot Newsletter
Your Email Address:

Storing Images In MySQL

Isn't This A Bad Idea?

This argument continues to rage and many lives have been lost trying to prove that this is a Bad Idea™. The facts are, this method of binary storage is very successful and has many advantages over filesystem storage. Some advantages are:

  • Referential integrity
  • Ease of backup
  • Saving of Inodes
  • Easy categorisation
  • Central point of operations

Many of the “nay sayers” will have you believe that storing of images or other binary data creates too much overhead. A large database can be stored on a RAW partition and in fact be faster as it has no filesystem overhead to contend with.

Some would say that access is slow when SELECTing from the database, but most of these issues are caused by coders doing things like:

Listing 1 listing-1.sql
select * from image_table

When all they needed was the image ID. You can see a benchmark of the perfomance of this where we used three methods of access for an image:

  • Access image from file
  • Store image in filesystem and store the url in the database
  • Store the image in the database

The results may surprise you.

In This Article


Tagged in ,

Article History

May 30, 2005
Initial article version
Jan 18, 2008
Updated listing 5 to not include non-existent conf.php