title: PHP PDO - getting image from MSSQL Database
body: <p>I've tried to get an image from an MSSQL Database. It's saved as "image"</p>
  
  <p>I've tried "image/png", "image/jpeg", "image/gif", "image" as Content Type.</p>
  
  <p>This is my code to get the Image(The $medi_conn comes from an included File):
       
  
  <pre><code>ini_set('display_errors', '1');
  error_reporting(E_ALL);
  
  if(isset($_GET['d']) &amp;&amp; is_numeric($_GET['d'])) {
      $sth = $medi_conn-&gt;prepare("SELECT Symbol FROM Dienstart WHERE DienstartID = :id") or die("Invalid query: " . $sth-&gt;errorInfo());
      $sth-&gt;bindParam(':id',  $_GET['d']);
      $sth-&gt;execute();
      $sth-&gt;bindColumn(1, $image, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY);
      $sth-&gt;fetch(PDO::FETCH_ASSOC);
  
      header("Content-type: image/jpeg;");
      echo $image;
  
  }
  else {
      echo 'Please use a real id number';
  }
  ?&gt;
  </code></pre>
  
  <p>This is an example of an Image:</p>
  
  <pre><code>0x89504E470D0A1A0A0000000D49484452000000140000001408060000008D891D0D000000097048597300000B1300000B1301009A9C180000000467414D410000B19E614C41F7000000206348524D00007A25000080830000F9FF000080E8000052080001155800003A970000176FD75A1F90000000EF4944415478DA62FCFFFF3F0335014000B180884F9F3E814DFDF7EF1F5986FCFEFD9BE1F3E7CF0C4A4A4A8C00010436F0C78F1F0C2097FEF9F3872C037FFEFCC970E6CC1990810C0001C402B30164188826073C7FFE9CE1D9B3676036400031315019000410D50D04082016420A9C37E66315DFEB3F11AB384000B1106B332E03D001400051DDCB000144B40B91BD8ECFB5000144752F030410D5BD0C10405437102080A86E204000B1502BEC60002080A8EE428000A2BA81000104F6F2AF5FBF185EBE7CC9F0EAD52BB20C79F7EE1DC3FBF7EFC16C8000021B78EEDC3930FEF6ED1BC52E040820466A5701000106001B39508BCCE3CEDB0000000049454E44AE426082
  </code></pre>
  
  <p>But this is the Result:</p>
  
  <pre><code>    �PNG
  
  ���
  IHDR�����������
  ��� pHYs����������gAMA����aLA���� cHRM��z%��������������R�X��:���o�Z�����IDATx�b���?5@����O�&gt;�M���Y���������JJJ��6�Ǐ �����,���p�������d�&amp;&lt;���ٳg`6@�11P��
   B
  �7�c��?�8@��k3.�@�Q���D����ϵ�Du/ս@T7 ��n @��P+�`� ���B���������_�^�|����+�y�������l��x��90����. FjW��9P���������IEND�B`�
  </code></pre>
  
  <p>Has anyone an idea?
  Thanks</p>