无法显示来自mysql数据库的blob数据

时间:2017-03-13 21:46:01

标签: php html mysql

所以我试图使用下面的PHP代码从数据库中显示BLOB数据,但它没有加载,在图片的位置我只能看到问号(缺席)。我做错了什么?我刚接触PHP btw。

<?php
    $query = "SELECT * FROM `blog_posts` LIMIT 0, 30 ";
    $result = mysqli_query($db, $query);
    while($row = mysqli_fetch_assoc($result)) {
        echo "<article>"; 
        echo    "<header>".$row["title"]."</header>"; 
        echo    "<div class='post-content'>";   
        echo        "<div class='post-image'><img src='data:image/jpeg;base64,".base64_encode($row["picture"])." width='290' height='290'></div>"; 
        echo        "<div class='post-text'>".$row["body"]."</div>"; 
        echo    "</div>"; 
        echo    "<div class='post-footer'>".$row["likes_number"]."  likes ".$row["comments_number"]."  comments"; 
        echo    "</div>";
        echo "</article>";
    }
?>

1 个答案:

答案 0 :(得分:1)

我认为问题是你在标签的src之后缺少一个结束的单引号

在src ='data之后添加':image / jpeg; base64,“。base64_encode($ row [”picture“])。”或试试这个 src="data:image/jpeg;base64,'.base64_encode($row['picture']).'"