472,106 Members | 1,359 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,106 software developers and data experts.

Pictures in mySQL

Hey guys,
I am creating a code out of bits and pieces I found in somebody else's
code, so I am not entirely sure how it behaves.

<IMG SRC="picture.php?ID=1029&THUMB=yes">

picture.php:
<?
Header( "Content-type: image/jpg");
$linkID = mysql_connect("host", "user", "password");
mysql_select_db("database", $linkID);
if(isset($_GET['ID'])){$ID=$_GET['ID'];}else{$ID=0;}
$result=mysql_query("SELECT * FROM picture_base WHERE ID=$ID") or
die("Can't perform Query");
$row=mysql_fetch_object($result);
if(isset( $_GET['THUMB']){echo $row->THUMB}else{echo $row->IMG;}
?>
The script works and displays pictures properly so I am happy with it.
Its small and simple enough, my question is if not every site is
saving their pictures in databases there must be a reason why, yes?
And if I load picture.php?ID=1029&THUMB=yes as opposed to picture.php?
ID=1029, will the script still load through the full sized image (in
the IMG collum) and will that effect my traffic?

thank you

May 1 '07 #1
9 2356
On Apr 30, 8:39 pm, blessblessbl...@gmail.com wrote:
Hey guys,
I am creating a code out of bits and pieces I found in somebody else's
code, so I am not entirely sure how it behaves.

<IMG SRC="picture.php?ID=1029&THUMB=yes">

picture.php:
<?
Header( "Content-type: image/jpg");
$linkID = mysql_connect("host", "user", "password");
mysql_select_db("database", $linkID);
if(isset($_GET['ID'])){$ID=$_GET['ID'];}else{$ID=0;}
$result=mysql_query("SELECT * FROM picture_base WHERE ID=$ID") or
die("Can't perform Query");
$row=mysql_fetch_object($result);
if(isset( $_GET['THUMB']){echo $row->THUMB}else{echo $row->IMG;}
?>
The script works and displays pictures properly so I am happy with it.
Its small and simple enough, my question is if not every site is
saving their pictures in databases there must be a reason why, yes?
And if I load picture.php?ID=1029&THUMB=yes as opposed to picture.php?
ID=1029, will the script still load through the full sized image (in
the IMG collum) and will that effect my traffic?

thank you
I save all my images in a folder as it reduces stress on the database
server. However, they are stored outside of public view. Php can then
show the images when requested. As for your second question, it really
depends on your setup. If you designed the script to display the full
view if you didn't request a thumb, then it would, or at least should,
work as stated above.

May 1 '07 #2
And if I load picture.php?ID=1029&THUMB=yes as opposed to picture.php?
ID=1029, will the script still load through the full sized image (in
the IMG collum) and will that effect my traffic?
yes that appears to be what it does.. if you load a full sized image
then yes it will have a greater affect on your bandwidth and traffic
useage than just a thumbnail.. when someone requests a thumbnail from
you the server shrinks it locally so its not using any traffic other
than displaying the thumbnail.

Flamer.
May 1 '07 #3
thank you you two.
i understand now that it will run the image locally and only display
the thumb.
but what is this stress on database, as of when is it considered
stressful? when loading 20 thumbs at the same time? or when hundreds
of people look at it at the same time?
this is just for a private portfolio of a photographer. so its not
aimed at the masses.
will this picture be stored temporarily on a private persons computer
like with normal images, or will it load new every a person visits the
page another time?
bless

May 1 '07 #4
>but what is this stress on database, as of when is it considered
>stressful? when loading 20 thumbs at the same time? or when hundreds
of people look at it at the same time?
Both..the database will run flat out trying to serv either case...you
will need a reasonably fast pc/db to do either (well)!

The "stress" on the database is due to it's field size. The Images
will need to be stored in a blob field or equivelant and that takes up
a substantial amount of space in the database which may reduce search
times etc. If your database is properly indexed and you dont have
thousands of images in the db then this shouldn't really cause a
problem.

I've used both methods in the past (db & file) and I have to say that
I prefer doing things with the file system...it make for easier
maintenance!

May 1 '07 #5
On May 1, 4:39 am, blessblessbl...@gmail.com wrote:
Hey guys,
I am creating a code out of bits and pieces I found in somebody else's
code, so I am not entirely sure how it behaves.

<IMG SRC="picture.php?ID=1029&THUMB=yes">

picture.php:
<?
Header( "Content-type: image/jpg");
$linkID = mysql_connect("host", "user", "password");
mysql_select_db("database", $linkID);
if(isset($_GET['ID'])){$ID=$_GET['ID'];}else{$ID=0;}
$result=mysql_query("SELECT * FROM picture_base WHERE ID=$ID") or
die("Can't perform Query");
$row=mysql_fetch_object($result);
if(isset( $_GET['THUMB']){echo $row->THUMB}else{echo $row->IMG;}
?>
The script works and displays pictures properly so I am happy with it.
Its small and simple enough, my question is if not every site is
saving their pictures in databases there must be a reason why, yes?
And if I load picture.php?ID=1029&THUMB=yes as opposed to picture.php?
ID=1029, will the script still load through the full sized image (in
the IMG collum) and will that effect my traffic?

thank you
it might be worth googling for sql injection attacks, and follow good
practice with the code.
$ID=$_GET['ID']
mysql_query("SELECT * FROM picture_base WHERE ID=$ID") !!
also lookup mysql_real_escape_string() if php5

May 1 '07 #6
bl*************@gmail.com wrote:
Hey guys,
I am creating a code out of bits and pieces I found in somebody else's
code, so I am not entirely sure how it behaves.

<IMG SRC="picture.php?ID=1029&THUMB=yes">

picture.php:
<?
Header( "Content-type: image/jpg");
$linkID = mysql_connect("host", "user", "password");
mysql_select_db("database", $linkID);
if(isset($_GET['ID'])){$ID=$_GET['ID'];}else{$ID=0;}
$result=mysql_query("SELECT * FROM picture_base WHERE ID=$ID") or
die("Can't perform Query");
$row=mysql_fetch_object($result);
if(isset( $_GET['THUMB']){echo $row->THUMB}else{echo $row->IMG;}
?>
The script works and displays pictures properly so I am happy with it.
Its small and simple enough, my question is if not every site is
saving their pictures in databases there must be a reason why, yes?
And if I load picture.php?ID=1029&THUMB=yes as opposed to picture.php?
ID=1029, will the script still load through the full sized image (in
the IMG collum) and will that effect my traffic?

thank you
I've been storing everything from scanned documents to pictures in
databases for over 20 years. It works fine. And the larger the number
of images, the better it outperforms a file system.

For instance - how many file systems do you know can manage 100K files
in a single directory? A RDB can easily handle 10M pictures. There's
no "stress" on the database. But it can be a lot of "stress" on a file
system.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
May 1 '07 #7
On May 1, 5:58 am, blessblessbl...@gmail.com wrote:
thank you you two.
i understand now that it will run the image locally and only display
the thumb.
but what is this stress on database, as of when is it considered
stressful? when loading 20 thumbs at the same time? or when hundreds
of people look at it at the same time?
this is just for a private portfolio of a photographer. so its not
aimed at the masses.
will this picture be stored temporarily on a private persons computer
like with normal images, or will it load new every a person visits the
page another time?
bless
you will be lucky if you can get 100 simultaneous requests! actually
most simple (non-load-blanced) web servers wouldnt handle that many.
the stress would come if each picture was large, not because the
database couldnt handle them - after all a table is a file somewhere
on a filesystem, but because if the database lives on another machine,
you will have to set up a TCP connection, and retrieve the data across
the network, then output to the client.
SQL was designed partly to stop the need for huge chunks of data
travelling across the network to be sorted, instead SQL sorted the
data and only sent what was needed. In the same way, /IF/ you organise
your pictures properly on the local filesystem (N directories each
with a sensible max limit, a non system disk for pure data storage
etc. etc..), set up the web server properly, retrieval will be faster,
perhaps easier to maintain and backup.
however as you scale up you will find your pictures are "non-local"
anyway, so a distributed database is an equivalent option after all!

May 1 '07 #8
On May 2, 12:18 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
blessblessbl...@gmail.com wrote:
Hey guys,
I am creating a code out of bits and pieces I found in somebody else's
code, so I am not entirely sure how it behaves.
<IMG SRC="picture.php?ID=1029&THUMB=yes">
picture.php:
<?
Header( "Content-type: image/jpg");
$linkID = mysql_connect("host", "user", "password");
mysql_select_db("database", $linkID);
if(isset($_GET['ID'])){$ID=$_GET['ID'];}else{$ID=0;}
$result=mysql_query("SELECT * FROM picture_base WHERE ID=$ID") or
die("Can't perform Query");
$row=mysql_fetch_object($result);
if(isset( $_GET['THUMB']){echo $row->THUMB}else{echo $row->IMG;}
?>
The script works and displays pictures properly so I am happy with it.
Its small and simple enough, my question is if not every site is
saving their pictures in databases there must be a reason why, yes?
And if I load picture.php?ID=1029&THUMB=yes as opposed to picture.php?
ID=1029, will the script still load through the full sized image (in
the IMG collum) and will that effect my traffic?
thank you

I've been storing everything from scanned documents to pictures in
databases for over 20 years. It works fine. And the larger the number
of images, the better it outperforms a file system.

For instance - how many file systems do you know can manage 100K files
in a single directory? A RDB can easily handle 10M pictures. There's
no "stress" on the database. But it can be a lot of "stress" on a file
system.

You raised an interesting point here I am working on a project
currently with around 10million photos, some folders have 20k+ photos
in each, ranging from a few hundred kbs to 6mb each.. would you
recommend using a database over files? Would MySQL be suitable?

Flamer.

May 4 '07 #9
flamer di******@hotmail.com wrote:
On May 2, 12:18 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
>blessblessbl...@gmail.com wrote:
>>Hey guys,
I am creating a code out of bits and pieces I found in somebody else's
code, so I am not entirely sure how it behaves.
<IMG SRC="picture.php?ID=1029&THUMB=yes">
picture.php:
<?
Header( "Content-type: image/jpg");
$linkID = mysql_connect("host", "user", "password");
mysql_select_db("database", $linkID);
if(isset($_GET['ID'])){$ID=$_GET['ID'];}else{$ID=0;}
$result=mysql_query("SELECT * FROM picture_base WHERE ID=$ID") or
die("Can't perform Query");
$row=mysql_fetch_object($result);
if(isset( $_GET['THUMB']){echo $row->THUMB}else{echo $row->IMG;}
?>
The script works and displays pictures properly so I am happy with it.
Its small and simple enough, my question is if not every site is
saving their pictures in databases there must be a reason why, yes?
And if I load picture.php?ID=1029&THUMB=yes as opposed to picture.php?
ID=1029, will the script still load through the full sized image (in
the IMG collum) and will that effect my traffic?
thank you
I've been storing everything from scanned documents to pictures in
databases for over 20 years. It works fine. And the larger the number
of images, the better it outperforms a file system.

For instance - how many file systems do you know can manage 100K files
in a single directory? A RDB can easily handle 10M pictures. There's
no "stress" on the database. But it can be a lot of "stress" on a file
system.


You raised an interesting point here I am working on a project
currently with around 10million photos, some folders have 20k+ photos
in each, ranging from a few hundred kbs to 6mb each.. would you
recommend using a database over files? Would MySQL be suitable?

Flamer.
Yep, databases work well for this kind of thing, if they're structured
correctly. And MySQL will do a good job for you.

But you really should be asking this in comp.databases.mysql.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
May 4 '07 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by JakeC | last post: by
13 posts views Thread by gooze | last post: by
9 posts views Thread by C.Joseph Drayton | last post: by
3 posts views Thread by Michael martin | last post: by
8 posts views Thread by cbmeeks | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.