使用PHP在表中显示MySQL数据库BLOB映像

时间:2016-05-06 05:02:46

标签: php mysql image blob display

我知道我使用折旧的MySQL,页面会很重,我应该将图像文件链接到数据库而不是直接插入它们。 除此之外,我在从数据库表中显示BLOB图像时出现问题" build"在列"图像"。

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

PHPMyAdmin图片:enter image description here

网页显示:enter image description here

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);

感谢您的帮助,我已经在这方面苦苦挣扎了几个小时。

1 个答案:

答案 0 :(得分:0)

$ row未定义,那么如何从

获取索引图像

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

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