简体   繁体   English

显示来自MySql数据库PDO的图像时出现问题

[英]Problem displaying images from MySql database PDO

I got a problem while displaying the images from MySQL Database. 显示来自MySQL数据库的图像时出现问题。 When I load the page, only the empty image element is loaded but not the actual image coming from database. 当我加载页面时,仅加载空图像元素,而不加载来自数据库的实际图像。 I think that php code is not correct. 我认为PHP代码不正确。

<?php 

 //connection do db
require_once __DIR__.'/connect.php';

try{
     $stmt = $db->prepare('SELECT * FROM pictures');
     $stmt->execute();
     if($stmt->rowCount()>0)
     {
         while($row=$stmt->fetchColumn())
         {
             extract($row);
;         }
     } 

}catch (PDOEXception $ex){
    echo $ex;
}
?>
<img src="images/<?php echo $row['path']?>"> 

You have to create <img> tags in while loop. 您必须在while循环中创建<img>标签。 Try: 尝试:

while($row=$stmt->fetchColumn())
{
    extract($row);
    echo '<img src="images/'.$row['path'].'">'; 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM