从数据库中检索 longblob 时出错 [英] Error Retrieving longblob from Database

查看:61
本文介绍了从数据库中检索 longblob 时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照教程显示数据库中的图像,这就是我的数据库中的表的样子.我做错了什么?

显示+-------+------------+------------+|索引 |显示_ID |图片 |+-------+------------+------------+|1 |12 |长斑点|+-------+------------+------------+

<小时>

<代码>><img src="show_image.php?image_id=12 <?php echo>$row_getdetails['image_id'];?>" alt="来自数据库的图像"/>

<块引用>

错误:> 您的 SQL 语法有错误;检查手册对应于您的 MySQL 服务器版本以使用正确的语法在第 2 行的 '' 附近

解决方案

好吧,据我所知,您的表中没有 mimetype 字段.这可能会导致错误 + 如果您的数据库有字段 Picture,不要要求名为 PICTURE 的字段.

I followed a tutorial to display image from the database, this is what the table looks like in my database. What am I doing wrong?

Display
+-------+------------+----------+
| Index | Display_ID | Picture  |
+-------+------------+----------+
|     1 |         12 | longblob |
+-------+------------+----------+

 

<?php
if (!function_exists("GetSQLValueString"))
 {
function GetSQLValueString($theValue, $theType, 
$theDefinedValue = "", $theNotDefinedValue = "")
{
 // function definition omitted
}
}

$colname_getImage = "-1";
if (isset($_GET['image_id'])) 
{
  $colname_getImage = $_GET['image_id'];
}
$db = mysql_connect("localhost", "root");
mysql_select_db("draftdb",$db);
$query_getImage = sprintf("SELECT mimetype, PICTURE FROM display
WHERE DISPLAY_ID = %s", GetSQLValueString($colname_getImage, "int"));
$getImage = mysql_query($query_getImage, $db) or
die(mysql_error());
$row_getImage = mysql_fetch_assoc($getImage);
$totalRows_getImage = mysql_num_rows($getImage);
mysql_free_result($getImage);

header('Content-type: image/jpeg ' . $row_getImage['mimetype']);
echo $row_getImage['image'];

?>


> <img src="show_image.php?image_id=12 <?php echo
> $row_getdetails['image_id']; ?>" alt="Image from DB" />

ERROR: > You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 2

解决方案

Well, as far as I see, there is no field mimetype in your table. That might cause the error + if your database has field Picture, don't ask for a field named PICTURE.

这篇关于从数据库中检索 longblob 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆