HY。
我想显示mysql数据库中的图片。 Php代码:
<body>
<?
$dbconn = @mysql_connect(localhost,root,xxx) or exit("SERVER Unavailable");
@mysql_select_db(test,$dbconn) or exit("DB Unavailable");
echo "Hallo";
$sql = "SELECT pictures FROM pictures where pictures_id = 1";
$result = @mysql_query($sql,$dbconn) or exit("QUERY FAILED!");
$image = @mysql_result($result,0,"pictures");
Header ("Content-type: image/jpg");
echo $image;
mysql_close($dbconn);
?>
</body>
MySql表:
CREATE TABLE IF NOT EXISTS `pictures` (
`pictures_id` int(11) NOT NULL AUTO_INCREMENT,
`pictures` blob NOT NULL,
PRIMARY KEY (`pictures_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
INSERT INTO `pictures` (`pictures_id`, `pictures`) VALUES
(1, too long to write the bytecode)
我刚刚手动插入了一张图片。
错误是没有任何事情发生。
答案 0 :(得分:1)
函数调用中的所有字符串参数都应该用引号括起来。
$dbconn = @mysql_connect(localhost,root,xxx);
应该是
$dbconn = mysql_connect('localhost','root','xxx');
等