image manipulation php mysql blob type

Ask about a PHP problem here.
Post Reply
patraghost
Posts: 5
Joined: Mon May 30, 2011 3:23 pm

image manipulation php mysql blob type

Post by patraghost »

hello there! i got a question about blob mysql data.i have a button and on buttonclick i want to open a popup (and passing date parameter) and show some details and display a photo.if i try
[syntax=php]<?php
if (isset($_GET['p'])){
$temp_date=$_GET['p'];
echo "DATE : $temp_d <br>";
$connect=mysql_connect("localhost","user","pass")
or die ("Check your server connection");
$db_found = mysql_select_db("mydb", $connect);
$SQL = "SELECT * FROM mytable
WHERE date =$temp_d";
$result = mysql_query($SQL);
$row=mysql_fetch_array($result);
echo "Details: $row[details]<br>";
$content = $row['image'];
header('Content-type:image/jpg');
echo $content;
} ?>
[/syntax]
its not working.in firefox its shows the name of the script+parameter and in IE opens a download box
If i try
[syntax=php]<?php
$connect=mysql_connect("localhost","user","pass")
or die ("Check your server connection");
$db_found = mysql_select_db("mydb", $connect);
$SQL = "SELECT * FROM mytable
WHERE id=1";
$result = mysql_query($SQL);
$row=mysql_fetch_array($result);
$content = $row['image'];
header('Content-type:image/jpg');

} ?>[/syntax]
its shows my stored image.how to pass the parameter and show the results to ? i dont know how thats possible but if i dont put
echo $content; i got my data (from other echoes) .how to have both image echo and details echo ?? tnx in advance
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: image manipulation php mysql blob type

Post by jacek »

Storing images this way is basically terrible. you should give up on this method develop something that uses files.
Image
patraghost
Posts: 5
Joined: Mon May 30, 2011 3:23 pm

Re: image manipulation php mysql blob type

Post by patraghost »

but generally its kind of convinient to me for the specific site i develop ! can you help me pls ?
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: image manipulation php mysql blob type

Post by jacek »

It can't be any more convenient than just storing the image name in the table and using files.

Seriously, this method is really not very good and you need to not use it.
Image
Dominion
Posts: 32
Joined: Thu May 05, 2011 11:32 pm

Re: image manipulation php mysql blob type

Post by Dominion »

You may want to explain that loading time for stored images is ridiculously high, and the it's been designed to store data not images rather then just saying it's bad?
Your best bet it to store the files. If you need the path to the files in the database so be it.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: image manipulation php mysql blob type

Post by jacek »

Dominion wrote:You may want to explain that loading time for stored images is ridiculously high, and the it's been designed to store data not images rather then just saying it's bad?

Actually I'm not saying that because the loading times would not be that high, and an image is just data.

the reason I am saying it's not a good idea is that it will add extra load to the mysql server than just using files would, meaning you will need to upgrade the servers pretty quickly. Also it means that the database size will grow very quickly whcih may eventually become a problem.
Image
Dominion
Posts: 32
Joined: Thu May 05, 2011 11:32 pm

Re: image manipulation php mysql blob type

Post by Dominion »

The extra load is why loading time become ridiculously high. Yes a picture is just data, but not data this type of database is optimized for.
Post Reply