从数据库检索longblob时出错
问题描述:
我按照教程显示数据库中的图像,这就是我的数据库中表的样子。我究竟做错了什么?从数据库检索longblob时出错
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
答
嘛,据我看到的,是表中没有现场mimetype
。如果您的数据库有字段Picture
,那么可能会导致错误+,请勿要求输入名为PICTURE
的字段。
在执行它之前echo $ query_getImage。 规则编号1,2和3调试动态创建的查询时:回显它们并直接对您的数据库执行它们,并找出您做错了什么。 – 2012-07-27 07:19:00
对不起,我对PHP比较陌生,我在哪里执行这一行,你能更详细地解释它吗? – Undermine2k 2012-07-27 07:24:03
欢迎来到Stack Overflow!请不要将'mysql_ *'函数用于新代码。他们不再被维护,社区已经开始[弃用流程](http://goo.gl/KJveJ)。请参阅[**红框**](http://goo.gl/GPmFd)?相反,您应该了解[准备好的语句](http://goo.gl/vn8zQ)并使用[PDO](http://php.net/pdo)或[MySQLi](http://php.net/ mysqli的)。如果你不能决定,[本文](http://goo.gl/3gqF9)将有助于选择。如果你关心学习,[这里是很好的PDO教程](http://goo.gl/vFWnC)。 – 2012-07-27 07:25:31