CGI-script: Loading pictures (BLOB) from an Oracle database ???

R

Robert Nilsson

Hi there

Does anyone here know how I should load a display from a Oracle database and
display it? I'm working on a DVD database over my own DVD's and I'd like to
show a picture together with each title.

Right now; I only got the text fields. It's like this:

--------------------------------------------------------------------------

#!/usr/bin/perl -w

use CGI ':standard';
use DBI;

$ENV{"ORACLE_HOME"} = "/opt/oracle/product/9.0.1";

$vendor = "Oracle";
$host =;
$sid = ;
$user =;
$pw =";

$dbh = DBI->connect("dbi:$vendor:host=$host;sid=$sid", $user, $pw);
$select = $dbh->prepare("select title, director, genre, length, starring
from dvd where hidden is null order by title");
$select->execute;

print header;

print start_html('-title' => 'DVD Movies',
'-bgcolor' => 'white');

print "<table border=2 bgcolor=FFFCC>";

print TR( td("Title"), td("Director"), td("Genre"), td("Length"),
td("Starring") );

while (@dvd = $select->fetchrow()) {
print TR( td($dvd[0]), td($dvd[1]), td($dvd[2]), td($dvd[3]),
td($dvd[4])),"\n";
}

print "</table>";

print end_html;
 
M

Matt Garrish

Robert Nilsson said:
Hi there

Does anyone here know how I should load a display from a Oracle database and
display it? I'm working on a DVD database over my own DVD's and I'd like to
show a picture together with each title.

If I understand you right, the common practice is to store the url of the
picture you want displayed in the database and then place that inside an
<img> tag. Storing the the actual image itself will bloat your database, and
especially in a case like you're describing, is not the means to the end
you're looking for...

Matt
 
G

Gregory Toomey

Robert said:
Hi there

Does anyone here know how I should load a display from a Oracle database
and display it? I'm working on a DVD database over my own DVD's and I'd
like to show a picture together with each title.

Load a display? What on earth is that?
Do you want to show a gif, jpeg, movie?

If you want to disply a gif in the browser, just write to to a file on your
web server and have the URL references it.

gtoomey
 
S

Sherm Pendley

Does anyone here know how I should load a display from a Oracle database and
display it? I'm working on a DVD database over my own DVD's and I'd like to
show a picture together with each title.

Put the "R" in "RDBMS" by creating a relationship between tables. Create a
separate table that holds only the image BLOBs, and assign a unique ID to
each of them. In your "main" table, simply store the ID, not the image
data.

When you're creating your HTML, retrieve the ID and use it to construct a
link to a CGI as the src attribute of an img tag, so that it looks
something like this:

<img src="showimage.cgi?id=abc123" />

In "showimage.cgi" you want to use the incoming ID to retrieve the BLOB
data from the images table and send it to the browser. Be sure to send the
appropriate MIME type - probably "image/jpeg", but it depends on what kind
of images you're storing.

sherm--
 
J

Juha Laiho

Sherm Pendley said:
Put the "R" in "RDBMS" by creating a relationship between tables. Create a
separate table that holds only the image BLOBs, and assign a unique ID to
each of them. In your "main" table, simply store the ID, not the image
data.

Actually if you consider one table row containing base information on a
single DVD, then the image BLOB suits just fine as one column of that
same table - I'd say forcing it to a separate table just because it's
an image would be forgetting the 'R'.

Of course this doesn't change anything on the HTML side - so the script
generating the table listing will still generate the <IMG> tags, as you
propose, and the browser will fetch them via some CGI. So, the difference
is just in the code of this handling CGI - whether it accesses a separate
table, or just the BLOB column of the same table where the rest of the
basic information was.

Where a table relation might be proper would be the 'starring' column, esp.
if the actor names were used as link anchors to provide something related
to the single actor (f.ex. a table of all movies where this single actor
plays).
In "showimage.cgi" you want to use the incoming ID to retrieve the BLOB
data from the images table and send it to the browser. Be sure to send the
appropriate MIME type - probably "image/jpeg", but it depends on what kind
of images you're storing.

Actually a good idea would be to store the MIME type along as one column
beside the image - this way you'd be free to use several image types.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top