Расширение ответа onteria. Если ваш движок БД имеет функциональность большого объекта (LOB), вам дополнительно нужно прочитать:
http://php.net/manual/en/pdo.lobs.php
<?php
$db = new PDO('odbc:SAMPLE', 'db2inst1', 'ibmdb2');
$stmt = $db->prepare("select contenttype, imagedata from images where id=?");
$stmt->execute(array($_GET['id']));
$stmt->bindColumn(1, $type, PDO::PARAM_STR, 256);
$stmt->bindColumn(2, $lob, PDO::PARAM_LOB);
$stmt->fetch(PDO::FETCH_BOUND);
header("Content-Type: $type");
fpassthru($lob);
?>
Это позволит избежать загрузки всего большого объекта в память за один раз.