title: how mssql image data type works with php pdo
body: <p>I have an MSSQL database with a table which contains data of images (image data type). (Uploaded and successfully used by another non-php-base program.) I would like to show/print these image through my php script.</p>
  
  <p>Based on the answer of <a href="https://stackoverflow.com/questions/5999466/php-retrieve-image-from-mysql-using-pdo">PHP: Retrieve image from MySQL using PDO</a> . The query works well, but it doesn't show the image only the "no-image" icon. </p>
  
  <pre><code>$sql = "SELECT image FROM image WHERE imageid=:id";
  $query = $db_conn-&gt;prepare($sql);
  $query-&gt;execute(array(':id' =&gt; $image_id));
  
  $query-&gt;bindColumn(1, $image, PDO::PARAM_LOB);
  $query-&gt;fetch(PDO::FETCH_BOUND);
  header("Content-Type: image/jpeg");
  echo $image;
  </code></pre>
  
  <p>Without the 7th line (header();) It shows something like this:</p>
  
  <pre><code>424df630030000000000360000002800000008010000c60000000100200000000000c0300300000000000000000000000000000000004c5d7e004b637f004f6081004d6180004d62820050...
  </code></pre>
  
  <p>In my Microsoft SQL Server Management Studio Express it look like this:
  <img src="https://i.stack.imgur.com/Y2w8e.jpg" alt="image data in Microsoft SQL Server Management Studio Express"></p>