2016-05-06 68 views
0

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

这是我的代码:显示打开和关闭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); 

感谢您的帮助,我一直在挣扎了这一小时。

+0

索引图像试试这个链接(http://stackoverflow.com/questions/20556773/php-display-image-blob-from-mysql) – developersaumya

+0

@SaumyaSingh我试过这个,我仍然卡住了。 – Aramza

+0

告诉我们什么是你面临的错误或问题? – developersaumya

回答

0

$行没有定义则u怎样才能从

您已经赚得了所有的MySQL的结果变量命名为$项,以便使用$项[“形象”]

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