title: Php - Display image from Database using path (PDO)
body: <p>I tried to display image from database,</p>
  
  <ul>
  <li>image in directory</li>
  <li><p>path in database</p>
  
  <pre><code>require_once "Connection.php";
  class DisplayDataImageProfile {
  function showImageProfile(){
      $connection = new Connection();
      $conn = $connection-&gt;getConnection();
  
      $id = $_GET['id'];
  
      try{
          $sqlDisplay = "SELECT photo FROM frofile WHERE id =$id";
          $getImage = $conn-&gt;prepare($sqlDisplay);
          $getImage-&gt;execute();
          $getImage-&gt;fetchAll(PDO::FETCH_ASSOC);
  
          foreach($getImage as $data){
              header('Content-type: image/jpg');
              // echo "&lt;img src='$data'&gt;";
              echo $data;
          }
  
      }catch (PDOException $e){
          echo "Error : " + $e-&gt;getMessage();
      }
  }}
  </code></pre></li>
  </ul>
  
  <p>after that i call in html page like this :</p>
  
  <pre><code>&lt;img src="DisplayDataImageProfile .php?id=3" align="center" /&gt;
  </code></pre>
  
  <p>i got problem that image cannot retrieve from database using path.
  other case on webpage the image something like broken image displayed.</p>
  
  <p>for currently i just display one image.</p>