1

我已经使用 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>
4

2 回答 2

0

不要将图像作为 BLOB 直接存储到数据库中。只需将它们存储为文件,并且仅将文件名存储在数据库中。

于 2013-10-08T10:45:22.480 回答
-1

我用谷歌搜索并找到了一些可以解决您问题的链接。参考这些链接:

http://www.phpro.org/tutorials/Storing-Images-in-MySQL-with-PHP.html

http://www.coderslexicon.com/inserting-images-into-mysql-and-retrieving-them-using-php/

http://pujanpiya.com.np/?q=node/25

于 2013-10-08T13:37:24.080 回答