View Full Version : PHP and Images

01-25-2007, 02:06 PM

I am having problems finding a site to instruct me on how to retrieve images from a MySQL database, I wonder if anyone could help me. This is the sql of the table used to store the images.

CREATE TABLE `images` (
`PremTeamID` mediumint(15) NOT NULL,
`ImageID` mediumint(15) NOT NULL auto_increment,
`ImageName` varchar(15) collate latin1_general_ci NOT NULL,
`Image` blob NOT NULL,

I am totally lost on how to retrieve the images. Any example scripts would be really useful. thanks.

01-25-2007, 07:40 PM
Here's a link that contains a pretty good explanation why storing images in blob type fields is a bad idea:

mysql forum post (http://forums.mysql.com/read.php?52,111593,112059#msg-112059)

But if you still want to, the way to do it is via imagecreatefromstring() (http://www.php.net/manual/en/function.imagecreatefromstring.php).

01-25-2007, 08:05 PM
That explanation isn't very good, misses out options that involve DB storage, but not a PHP-based rendering. An example:

page is loading,
code looks up which images are associated with the page,
checks to see if the images exist in the disk-cache,
if they don't it pulls them and puts them there,
the src in the img tags refers to this known cache location.
Avoids all the flaws that article mentions, and has the benefit that you can have the CMS system (where you upload the images) separate from the website, with a shared database.

We have a single CMS system for all our clients that is on a machine of it's own. The database is on a machine of its own. We have a separate 'farm' of load-balanced web-servers handling the sites.