简体   繁体   English

无法将Blob存储的图像转换为图像格式(MySql和php)?

[英]cant able to get the blob stored image into image format(MySql AND php)?

I am trying to get the image which is stored in the blob format in Mysql Database.I am using the following code. 我正在尝试获取以Blob格式存储在Mysql数据库中的图像。我正在使用以下代码。
index.php index.php

<img src='image.php?questionid=questionid&question=question1&answer=answer1&author=myname' />

image.php image.php

<?php
require_once('dbconfiguration.php');
$sql="SELECT image FROM tablename WHERE questionid='{$_GET['questionid']}' and question='{$_GET['question']}' and answer='{$_GET['answer']}' and author='{$_GET['author']}'";
$STH = $DBH->query($sql);  
$STH->setFetchMode(PDO::FETCH_ASSOC);  
$row = $STH->fetch();  
ob_clean();
header("content-type: image/jpg") ; 
echo $row['image'] ; 
?>

In index.php I didn't get any image.So When I enter the URL for image.php I am getting the following error in forefox. 在index.php中我没有得到任何图像。因此,当我输入image.php的URL时,我在forefox中收到以下错误。

The image “URL” cannot be displayed because it contains errors.

I am using php5.3 and mysql 5.1.36 . 我正在使用php5.3和mysql 5.1.36。

What I did wrong.I went through almost all forums and no clues.Please help me on this. 我做错了什么,我参加了几乎所有论坛,没有任何线索,请帮助我。

It should be: 它应该是:

<?php
require_once('dbconfiguration.php');
$sql="SELECT image FROM tablename WHERE questionid='{$_GET['questionid']}' and question='{$_GET['question']}' and answer='{$_GET['answer']}' and author='{$_GET['author']}'";
$STH = $DBH->query($sql);  
$STH->setFetchMode(PDO::FETCH_ASSOC);  
$row = $STH->fetch();  
ob_clean();
header("content-type: image/jpg") ; 
echo $row['image'] ; 
?>

As your database field is called image not Efaq_image 由于您的数据库字段称为image而不是Efaq_image

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM