Norman Peelman wrote:
"Andy Hassall" <an**@andyh.co.uk> wrote in message
news:el********************************@4ax.com... On Thu, 04 Aug 2005 23:54:11 +0300,
Alexey Kulentsov <cr*******@crimaniak.com> wrote:
Never store image in database. Database can't index images so you have
no any reason to store it in SQL server.
Untrue - two clear advantages are:
(1) The image data is under the same transactional control as
the rest of the data.
.... (2) Having the images in the database means you only have to
backup one thing,
I have to agree with Andy on this one... for both reasons he pointed out.
And most of the time you can pull in your image data right along with
everything else in the same query.
As a matter of fact, most of the time you can't do it. You need
a separate script to pose as a picture. So if you have a page
that pulls text data and references three images, you will have
four nearly simultaneous connections, one for the text page and
three for three instances of picture-rendering script.
This could quickly change at some point if all browsers begin to
understand the <img data=""> tag; then there will be no need for
separation of HTML and image output. Unfortunately, we are not
quite there yet...
There is also a workaround, whereby the HTML-rendering script
retrieves image data from the database and stores images in
session variables and then passes the variable names to
picture-rendering scripts, which retrieve image data not from
the database, but from the session variable referenced.
Andy is absolutely right when he says that storing images in a
database leads to stricter transactional control and easier data
maintenance. But the developer needs to understand that this
architecture creates additional overhead that cannot be overcome
from within PHP; Andy's proposed solution is to cache images,
which is another way of saying "store image copies on disk, but
keep normative versions in the database".
Actually, a similar approach is used by some content management
systems which allow for separation of authoring and publishing.
An author submits text and images; they are stored in a database.
When the editor publishes the submission, static HTML and image
files are created (not necessarily on the same physical machine).
Cheers,
NC