473,406 Members | 2,849 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 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 2434
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: NotGiven | last post by:
Please help me understand the big picture of allowing users to upload pictures and keep them separate and tied to their record in the database. I want the whole thing automated and I'm just...
3
by: NotGiven | last post by:
I am researching the best place to put pictures. I have heard form both sides and I'd like to know why one is better than the other. Many thanks!
0
by: JakeC | last post by:
Hey all, I'm currently redesigning a website that a friend and I started about a year ago. It is a daily surf report so when choosing the best script/language to use for the new design, I found...
3
by: Jim S. | last post by:
Hi guys, i have lots of data for products (with different categories) and pictures that i would need it entered into a database on the website. How would i go about doing so? i was thinking...
13
by: gooze | last post by:
Hello I am working on an applicaion that shows several pictures on a webpage. These pictures are saved in a MySQL DB as BLOB. I noticed, that the web server suffers in its performance by...
9
by: C.Joseph Drayton | last post by:
Hi All, I have a web site I am developing, and have a question. I would like members to be able to upload pictures. Do you think they should be saved as individual files or should they be put...
3
by: Michael martin | last post by:
I'm trying to create a picture database for a site that I'm working on and I would like to do the following: - (main goal) Have a php script load an entire directory of photos into my mysql...
8
by: cbmeeks | last post by:
I am writing my own family photo sharing site that I hope to take public (like so many others). Anyway, currently, when the user uploads a picture, I store the picture outside my htdocs folder and...
1
oranoos3000
by: oranoos3000 | last post by:
hi would you please help me i have a online shopping center that i show pictures of the my product in home page. in the InterExplorer pictures is shown correctly but in Firefox browser is shown...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.