title: I can' display an image from sql database with php. How is it possible to display it and how can I display more pictures at a time?
body: <p>I'm trying to display a picture from mysql database, but somehow it isn't working. The picture is in jpeg format. I use a simple php code with a database connect file and a source file. The weird thing is that if I want to download the picture directly from the database, it stays as a binary .bin file. Here are my codes: </p>
  
  <p>db_connect.php:</p>
  
  <pre><code>&lt;?php
  $dbh = new PDO('mysql:host=localhost;dbname=probe', $root);
  ?&gt;
  </code></pre>
  
  <p>source.php:</p>
  
  <pre><code>&lt;?php
  include ‘db_connect.php’;
  $query = “select * from users”;
  $stmt = $con-&gt;prepare( $query );t
  $stmt-&gt;bindParam($_GET['image']);
  $stmt-&gt;execute();
  $num = $stmt-&gt;rowCount();
  if( $num ){
      $row = $stmt-&gt;fetch(PDO::FETCH_ASSOC);
      header(“Content-type: image/jpeg”);
      print $row['image'];
      exit;
  }else{
      //if no image found with the given id,
      //load/query your default image here
  }
  ?&gt;
  </code></pre>
  
  <p>And in the index file I just call the source.php to display the picture:</p>
  
  <pre><code>&lt;img src="../reg/source.php" &gt;
  </code></pre>
  
  <p>This is the SQL source:</p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `users` (
        `id` int(11) NOT NULL AUTO_INCREMENT,
        `image` blob NOT NULL,
        `image_type` varchar(100) NOT NULL,
        `image_size` varchar(100) NOT NULL,
        `image_name` varchar(100) NOT NULL,
        PRIMARY KEY (`id`),
        KEY `name` (`name`)
      ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=44 ;
  </code></pre>