2

My client have created a script in php+mysql that saves images directly in the database and every images has url like this: www.example.com/image.php?id=421

In your opinion this is a very wrong solution ? Should I rebuild all the site ?

There are about 1000 visits per day and about 600 images in the database.

2
  • 2
    phpriot.com/articles/images-in-mysql/2 <-- you decide Commented May 2, 2010 at 10:54
  • @Gazler Following Link is not working. Its showing 404 in my end. Commented Jan 24, 2015 at 13:43

5 Answers 5

6

Images files are files, unless there is compelling reason to store them in the database, the place they belong is the file system, where you get benefits like easy backup and replication, distributed across multiple machines, directly served by the webserver, and all the last-modified-date and etag supported by the webserver to achieve better performance, etc.

if the number of images is expected to grow, and different sizes of one image are expected to be created (e.g. thumbnail images etc.) in the coming release, a plan to migrate images from db to file system is strongly suggested.

Sign up to request clarification or add additional context in comments.

Comments

3

Is there a good reason for storing them in the DB? There can be some valid reasons to do this. I am assuming these are client images not the images needed to display the site itself (i.e. background images, things inside img tags).

As for rebuilding the site. It would likely improve performance, but at a 1000 hits a day it may not be worth the time it would take. assuming site performance was acceptable and it did not incur extra hosting fees etc. I would be inclined to leave it until I was redesigning the site.

Comments

2

If you read @Gazler's link from comment, it really boils down to few questions:

  • is there any problem with performance? [Y]
  • do you store any additional information, or just images itself? [Just images]
  • do you plan (or hope) to attract much more users in future? [Y]
  • are you limited in size of your db? [Y]

if you answered with answers in brackets, then it might be good for your website to put images out of database, otherwise, you can leave it as it is and save yourself some time and/or nerves

Comments

2

Just because it can be done, doesn't mean it should be.

I always store meta data about the images (filename, location, other attributes) in the database, and store images externally in the file system. There is very little benefit, imo, of actually storing images in an SQL database. Once they are in there, they are very inconvenient to use.

Comments

1

There are good and bad points. And it depends on who you are. about 5 years ago it became all the rage to put all images in the database.

But with server space sizes bigger today, its not really about saving space.

A negative would be you will always require understanding of server side programming to use images. If this development my be passed to another person, it could prove problematic.

As far as I can see, if it works, it works and I can't see performance issues - it seems very quick.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.