php - 无法从数据库中读出图片,因为使用了外键

标签 php mysql database

<分区>

我的数据库有一个表 (a),其中我有一个 id 作为 PK 和一个图像表 (output_images),其中内容 id 来自 (a) 作为外键。

output_images 表:

image_id tinyint(3) NOT NULL AUTO_INCREMENT,

image_type varchar(25) NOT NULL,

imageData   mediumblob BINARY

a_ID int(11)

image.php 从数据库中获取每张图片:

<?php
mysql_connect("... .com","user","pw");
mysql_select_db("database");
if(isset($_GET['image_id'])) {
$sql = "SELECT imageType,imageData FROM output_images, a WHERE 
output_images.a_ID=a.a_ID" . $_GET['image_id'];
$result = mysql_query("$sql") or die("<b>Error:</b> Problem on Retrieving Image BLOB<br/>" . mysql_error());
$row = mysql_fetch_array($result);
header("Content-type: " . $row["imageType"]);
echo $row["imageData"];
}
mysql_close();
?>

listimages.php 调用 image.php 来构建图像列表:

        <?php
        mysql_connect("... .com","user","pw");
        mysql_select_db("database");
        $sql = "SELECT imageId FROM output_images,a Where output_images.a_ID=a.a_ID ORDER BY imageId DESC"; 
        $result = mysql_query($sql);
        ?>
        <HTML>
        <HEAD>
        <TITLE>List BLOB Images</TITLE>
        <link href="imageStyles.css" rel="stylesheet" type="text/css" />
        </HEAD>
        <BODY>
        <?php
        while($row = mysql_fetch_array($result) or die (mysql_error()) 
        {
        ?>
        <img src="image.php?image_id=<?php echo $row["imageId"]; ?>" /><br/>
        <?php       
        }
        mysql_close();
        ?>
        </BODY>
        </HTML>

实际错误信息:

Parse error: syntax error, unexpected '{' in home/a9996478/public_html/listImages.php on line 15

if i change the fifth line of listImages.php to:

$sql = "SELECT imageId FROM output_images ORDER BY imageId DESC";

我遇到了同样的问题,甚至我之前也遇到过这行 12 损坏的图片

我不知道是什么问题....

最佳答案

在 while 循环中缺少 )

 while($row = mysql_fetch_array($result) or die (mysql_error()) )// missing

关于php - 无法从数据库中读出图片,因为使用了外键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30754817/

相关文章:

php - 使用 PHP_SELF 在发布后保留变量值

SQL - 将一张表拆分为两张表并链接

python - 如何修复 : Cannot resolve keyword 'user' into field. 选择为 : description, end_time、id、start_time、title Django 错误

php - MySQL: from_unixtime: 访问被拒绝

javascript - 在 iMacros 中重新加载页面后,如何定位名称每次都在变化的表单输入字段?

php - 设置 MySQL 数据库以用于搜索功能

mysql - 如何在 MySQL 中使用自定义逻辑 IF 语句比较两列之间的值

php - php中的日期时间函数

mysql - 引导 Galera 集群失败

php - mysqli_stmt 无法转换为字符串