在PHP中显示来自MySQL数据库的Blob图像和标题

时间:2015-10-01 05:07:33

标签: php mysql

我知道这里有关于这个特定问题的其他帖子,但这些解决方案似乎都不适合我。我有一些图像和一个简短的标题由一个简单的表格加载到MySQL数据库。表单上传到数据库完全正常。我遇到的问题是使用PHP在页面上显示带有标题的多个图像。我有一张名为images_tbl的表 行idimageimage_title

以下是从数据库中提取信息的文件:

source.php

<?php
//include database connection
include 'db_connect.php';

//select the image
$image = mysql_query("SELECT * FROM images_tbl WHERE id = $id");
$stmt = $con->prepare($image);

//bind the id of the image you want to select
$stmt->bindParam(1, $_GET['id']);
$stmt->execute();

//to verify if a record is found
$num = $stmt->rowCount();
if( $num ){
//if found
$row = $stmt->fetch(PDO::FETCH_ASSOC);

//specify header with content type, 
header("Content-type: image/jpg");

//display the image data
print $row['image'];
print $row['image_title'];
exit;
}else{
//if no image found with the given id,
echo 'No image found!';
}
?>

这是显示数据库中图像的文件:

的index.php

<?php

//connect to the database//
//include database connection
include 'mysqlconnect.php';

while($row = mysql_fetch_assoc($image))
{
    echo '<img src="source.php?id='.$row["id"].'">';
    echo $row["image_title"];
}

mysql_close();

?>

我收到了错误:

  

警告: mysql_fetch_assoc()要求参数1为资源,第14行/public_html/index.php中给出布尔值

有什么想法吗?

0 个答案:

没有答案
相关问题