我使用phpmyadmim创建了一个数据库并访问它,我创建了一个name.php文件。
访问注册号,名称很简单,但图像检索不是这样。 我使用LongBlob作为类型通过phpmyadmin存储图像..但是我无法显示它..
如何检索图像?
如果有人可以提供帮助,我们将非常感激。
谢谢, LJ
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>PHYTOCHEMICAL DB</title>
<style type="text/css">
body {
font-family: Georgia, "Times New Roman",
Times, serif;
color: purple;
background-color: #EEEEEE}
</style>
</head>
<body>
<table width="800" border="" align="center">
<tr>
<td colspan="2" style="background-color:#FFA500;height:30px;width:700px">
<div> <img src="leaves.jpg" height="300" width="900"/> </div> <br/>
</td>
</tr>
<tr>
<td style="background-color:#FFD700;width:250px;">
<b>Menu</b><br>
<i> <a href="home.php">Home</a><br>
<i> <a href="did.php">Search by Database ID (DID)</a> <br>
<i><a href="mw.php">Search by Molecular weight<br>
</td>
<td style="background color:#EEEEEE;height:500px;width:800px;">
<form action="" method="POST">
<p> Enter the name </p>
<input type="text" name="pname">
<input type="submit" value="submit" name="submit1">
<br>
</form>
<?php
$mysqli = new mysqli("localhost", "root", "osddosdd", "phychem");
if (mysqli_connect_errno()) {
printf("Connect failed:%s\n", mysqli_connect_error());
exit();
}
if (isset($_POST['submit1'])) {
$pname = $_POST['pname'];
$query = ("select * from pchem where name LIKE '$pname'");
$result = $mysqli->query($query);
echo 'The retrieved query is:';
echo "<table border='1'>
<tr>
<th>DID</th>
<th>Name</th>
<th>Molecular weight</th>
</tr>";
while ($row = $result->fetch_row()) {
echo '<tr>';
printf("<th>%d</th> <th> %s </th> <th> %2f </th>", $row[0], $row[1], $row[2]);
echo '</tr>';
echo '</table>';
}
}
$mysqli->close();
?>
</td>
</table>
</body>
</html>
答案 0 :(得分:0)
不要将图像作为BLOB直接存储到数据库中。只需将它们存储为文件,只将文件名存储在数据库中。
答案 1 :(得分:-1)