通过php(pdo)从mysql数据库中选择longblob,然后将blob插入html`<img src="x"/>`标签中

时间:2019-02-09 13:34:17

标签: php html mysql pdo

我在通过php(pdo)选择mysql blob并通过<img src = "x"> html标签显示它时遇到问题。

到目前为止,这是我的代码:

    <?php
      $db = new Dbh;
      $pdo = $db->connect();
      $counter = 0;
      $content = "";

      $statement = $pdo->prepare('SELECT * FROM images');
      $statement->execute();

      while ($row = $statement->fetch()) {
        if (($counter % 3) == 0) { ?>
          <div class = "row" style = "width: 99%; margin-left: auto; margin-right: auto;">
        <?php } ?>
        <div class = "col" style = "padding: 5px;"><a class = "linkImage" href = "#"><img src = "<?php echo $row['image']; ?>" alt = "Bacteria" width = "100%"></a></div>

        <?php if (($counter % 3) == 2) { ?>
          </div>
        <?php }

        $counter ++;
      }

      if (($counter % 3) == 1) { ?>
        <div class = "col" style = "padding: 5px;"></div><div class = "col" style = "padding: 5px;"></div></div>
      <?php } elseif (($counter % 3) == 2) { ?>
        <div class = "col" style = "padding: 5px;"></div></div>
      <?php }
    ?>

由于某种原因html不接受echo $row['image'];或仅将$row['image']作为img源。

0 个答案:

没有答案