【问题标题】:Displaying MySQL database BLOB images in a table with PHP使用 PHP 在表中显示 MySQL 数据库 BLOB 图像
【发布时间】:2016-09-01 01:36:06
【问题描述】:

我知道我正在使用折旧的 MySQL,页面会很重,我应该将图像文件链接到数据库中,而不是直接将它们插入那里。 除此之外,我无法在“image”列中显示数据库表“builds”中的 BLOB 图像。

这是我的代码:显示打开和关闭 PHP 标记的问题。

PHPMyAdmin 图片:

网页显示:

include ("connect.php");
$conn = mysql_connect("localhost", $id, $pw); //Start of Establishing Connection to Database "akimble"
if (!$conn) {
    die ("Error connecting: " . mysql_error()); //Displays What the Error was if Present
}
mysql_select_db($db, $conn);
$sql = "SELECT * FROM builds"; //Selects Everything From the Table "userinfo" in "akimble" Database
$results = mysql_query($sql, $conn); //Assigning all Data

echo "<table cellpadding=10 border=1>
<tr>
    <th>User ID</th>
    <th>Image Name</th>
    <th>Image</th>
</tr>";

while ($entries = mysql_fetch_array($results)) { //Fetch all Information within "results" Variable
    echo "<tr>";
        echo "<td>" . $entries['id'] . "</td>";
        echo "<td>" . $entries['name'] . "</td>";
        header("Content-type: image/jpg");
        echo '<img src="data:image/jpg;base64,' . base64_encode( $row['image'] ) . '" />';
    echo "</tr>";
                                                }
echo "</table>";

mysql_close($conn);

感谢您的帮助,我为此苦苦挣扎了好几个小时。

【问题讨论】:

  • @SaumyaSingh 我已经尝试过了,但我仍然卡住了。
  • 告诉我们您面临的错误或问题是什么??
  • @SaumyaSingh 和以前一样的错误,目前没有显示图像。
  • 哦,你为什么用$row??虽然它不反对你应该使用$entries['image']

标签: php mysql image blob display


【解决方案1】:

$row 没有定义,那么你如何从中获取索引图像

您已将所有 mysql 结果提取到名为 $entries 的变量中,因此请使用 $entries['image']

 echo '<img src="data:image/jpg;base64,' . base64_encode( $entries['image'] ) . '" />';
echo "</tr>";

【讨论】:

    猜你喜欢
    • 2019-07-05
    • 2015-04-06
    • 1970-01-01
    • 2014-01-05
    • 2014-02-21
    • 2012-01-09
    • 2011-08-21
    • 2020-06-22
    • 2012-02-03
    相关资源
    最近更新 更多