Display a image stored in a database

images php coding issues or problems here.

Moderators: macek, egami, gesf

mcandrey
New php-forum User
New php-forum User
Posts: 10
Joined: Tue Mar 25, 2003 3:59 am
Location: bucharest-romania
Contact:

Display a image stored in a database

Postby mcandrey » Tue Mar 25, 2003 8:10 am

I use the folowing code to display a picture stored in a database in a long blob field:

<?php

$x=mysql_connect("localhost","root","");
mysql_select_db ("pic");

$q = "select CODE,PICT from test where CODE = '001'";
$qexec = @mysql_query($q) or die("Couldn't get image.");

$img = @mysql_result($qexec,0,"PICT");
mysql_close($x);
echo $img;

?>

This code is work, but if I insert in the page another character or the line echo "a character"; the pictures will not be displayed corectly.

Thx in advance.

User avatar
pootergeist
New php-forum User
New php-forum User
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK
Contact:

Postby pootergeist » Tue Mar 25, 2003 8:28 am

why are you storing the images in the database?
are you manipulating or searching the binary data very often?

due to images having header content, each must be requested with a new http call - so for every image pulled you are instantiating another database connection and incuring the overhead associated with so doing.

even mysql themselves advise totally against storing images in databases.

do yourself, your host and your visitors a favour and store the images as files in a folder somewhere - just store the associated information in the database.

mcandrey
New php-forum User
New php-forum User
Posts: 10
Joined: Tue Mar 25, 2003 3:59 am
Location: bucharest-romania
Contact:

Postby mcandrey » Tue Mar 25, 2003 11:27 pm

I use a large library with *.jpgs and, of course, I use a admin page to manipulate these. So, I thought that is a good ideea to store the *.jpgs in the database.

For what is longblob field dedicated? ... please let me have your recomandation pages/urls.

thx in advance


Return to “PHP coding => Images”

Who is online

Users browsing this forum: No registered users and 2 guests