PHP - 从数据库获取图像

时间:2015-03-14 06:32:28

标签: php android mysql

我想将用户的图像保存到数据库中。

p9_member(member_no,member_name,....,member_photo)

现在,我使用BLOB保存“member_photo”列的图像 我现在想做的是:
1.我有一个应用程序需要连接数据库并从数据库中获取图像 我也有一个网站做同样的事情 我现在正在实施该应用程序。因为我需要发送图像,其中包含名称或ID等成员的一些信息。所以我创建了一个保存所有东西的对象。这是我的PHP代码:

<?PHP
   Class Friends{
var $no;
var $name;
var $photo;
var $status;
var $admin;
public function __construct($no,$name,$photo,$admin,$status){
    $this->name = $name;
    $this->photo = $photo;
    $this->no = $no;
    $this->status=$status;
    $this->admin=$admin;
}
};
include ("../../server_config.php");
$friends = array();
$SQL = "SELECT p9_member.member_no,p9_member.photo AS     PHOTO,p9_member.name,p9_member.photo FROM p9_member, p9_friends WHERE p9_member.member_no = p9_friends.member_no2 AND p9_friends.member_no1 =".$_POST['memberno'];
$result = mysqli_query($con,$SQL);
if (mysqli_num_rows($result)>0) {
        while($row = mysqli_fetch_array($result)){
            $friends[] = new Friends($row['member_no'],$row['name'],$row['photo'],null,null);
        }
    }else
        $friends[] = 0;
    echo json_encode($friends);

?>

SQL CODE:

SELECT p9_member.member_no,p9_member.photo AS PHOTO
FROM p9_member, p9_friends 
WHERE p9_member.member_no = p9_friends.member_no2 
AND p9_friends.member_no1 =".$_POST['memberno']

json解码后,我无法从应用程序中获取数据。 对我来说最好的解决方案是什么?

1 个答案:

答案 0 :(得分:2)

尝试以下代码,它将起作用..

$image_qry=mysql_query("SELECT * FROM tabel_name WHERE your condition");
$image=mysql_fetch_assoc($image_qry);
$get_image=$image['image_column']; //BLOB DATA TYPE
header("Content-type: image/jpeg"); // need to add the header content type in your code
echo $get_image;