从数据库中检索longblob时出错

时间:2012-07-27 07:16:12

标签: php mysql

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

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" />
  

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

1 个答案:

答案 0 :(得分:0)

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

相关问题