<?php
 $host        = "host = 172.1.42.4";
   $port        = "port = 5432";
   $dbname      = "dbname = sac";
   $credentials = "user = postgres password = asr";

   $db = pg_connect( "$host $port $dbname $credentials"  );
   if(!$db) {
      echo "Error : Unable to open database\n";
   } 

$result = pg_query($db, "SELECT * FROM sac.images");
if (!$result) {
  echo "An error occurred.\n";
  exit;
}

while ($row = pg_fetch_array($result)) {
  $image = $row['data'];
}
header('Content-type: image/png');
  echo pg_unescape_bytea($image);

?>
