使用PHP从Mysql显示图像 [英] Displaying Image from Mysql with PHP

查看:76
本文介绍了使用PHP从Mysql显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的表在数据库中的外观.我正在尝试显示存储的图像是mimetype(longblob).当我运行代码时,它给了我一个带有?的小盒子. ,没有错误,只是那个盒子.有谁知道错误是什么以及我该如何解决?

This is what my table looks like in my database. I'm trying to display an image I stored it's a mimetype (longblob) . When I run the code it gives me a small box with a ? , no error just that box. Does anyone know what the error is and how I can fix it?

Display
+-------+------------+----------+
| Index | Display_ID | Picture  |
+-------+------------+----------+
|     1 |         12 | longblob |
+-------+------------+----------+


<?php
    $mysqli=mysqli_connect('localhost','root','','draftdb');


    if (!$mysqli)
        die("Can't connect to MySQL: ".mysqli_connect_error());

    $imageid= 12;

    $stmt = $mysqli->prepare("SELECT PICTURE FROM display WHERE DISPLAY_ID=$imageid"); 
    $stmt->bind_param("i", $imageid);

    $stmt->execute();
    $stmt->store_result();

    $stmt->bind_result($image);
    $stmt->fetch();

    header("Content-Type: image/jpeg");
    echo $image; 
?>

推荐答案

此:

$stmt = $mysqli->prepare("SELECT PICTURE FROM display WHERE DISPLAY_ID=$imageid");

应该是:

$stmt = $mysqli->prepare('SELECT PICTURE FROM display WHERE DISPLAY_ID=?');

您直接将变量嵌入查询中,而不是像您打算的那样实际使用绑定变量.

You were directly embedding the variable in the query instead of actually using the bound variables like you intended to.

这篇关于使用PHP从Mysql显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆