Sorry for double posting , posted 1 thread in the wrong forum because its obviously more related to php than sql.
database "dota2"
table "images"
id(int11)
pics(blob)
ext(varchar4)
gender(varchar7)
now i have 1 image stored "id" 5 "pics" [BLOB - 1.4 KiB] "ext" jpg "gender" china
storing code
PHP Code:
$con = mysql_connect("localhost","root","aa"); if (!$con) { die('Could not connect: ' . mysql_error()); }
$img = base64_encode($img); mysql_connect("localhost","root","aa") or die(mysql_error()); mysql_select_db("dota2") or die(mysql_error()); $sql = "INSERT INTO images(id, pics, ext, gender) values (null,'$img','jpg','china')"; mysql_query($sql) or die('Bad Query at 12'); echo "Success! You have inserted your picture!";
showing code
PHP Code:
header("Content-type: image/jpg"); $con = mysql_connect("localhost","root","aa") or die(mysql_error()); mysql_select_db("dota2"); $getImage = mysql_query("SELECT pics FROM images WHERE id = 5") or die(mysql_error()); $row_getImage = mysql_fetch_array($getImage, $con);
I'm not sure if i'm doing it right, i dont yet fully understand the actions of the mysql , i copied this code and tweaked a bit , the part i dont understand is
PHP Code:
$getImage = mysql_query("SELECT pics FROM images WHERE id = 5") or die(mysql_error()); $row_getImage = mysql_fetch_array($getImage, $con);
can i use simply $getImage to show the image without $row_getImage = mysql_fetch_array($getImage, $con);?
nevertheless, decoding failed getting the same error, or im doing it wrong.
PHP Code:
header("Content-type: image/jpg"); $con = mysql_connect("localhost","root","aa") or die(mysql_error()); mysql_select_db("dota2"); $getImage = mysql_query("SELECT pics FROM images WHERE id = 5") or die(mysql_error()); $row_getImage = mysql_fetch_array($getImage, $con); $row_getImage = base64_decode($row_getImage);
Fair enough. I'm just starting to learn mysql our college neglected to teach us. So now in my understanding i took the value i needed from the array and stored it in $img and decoded it. But the error is the same.
PHP Code:
$getImage = mysql_query("SELECT pics FROM images WHERE id = 5") or die(mysql_error()); $row_getImage = mysql_fetch_array($getImage, $con); $img = $row_getImage['pics']; $imgNew = base64_decode($img); echo $imgNew; mysql_free_result($imgNew);
I tried reading on that website but its to raw for me to understand yet.
I tried changing as you suggested but is till doesn't work. Im tired from trying to do this for almost half a day. Now im just storing the path to the image, in my noob opinion its not as good as storing image itself but at least it works for me.
Thank you all for trying to help.
OK. Well, if you feel like tackling it again tomorrow, give us the public URL of the script you're working on and a public URL for the image itself. Comparing the the difference in output might shed some light on the issue ...
... also, it may be worthwhile to re-insert the image in the database. And, if it's small, examine it with the command line client and show us the output of that as well.
Bookmarks