I am refactoring some old code, including rewriting basic mysql queries to use PDO.
The following works brilliantly in all browsers and for all image types:
You need to paramaterize the imageid value and bind the parameter to PDO::PARAM_LOB:
$sql = "SELECT image FROM image WHERE imageid=:id";
$query = $db_conn->prepare($sql);
$query->execute(array(':id' => $image_id));
$query->bindColumn(1, $image, PDO::PARAM_LOB);
$query->fetch(PDO::FETCH_BOUND);
header("Content-Type: image");
echo $image;
Of course, you'll also want to specify the complete, correct content type (e.g., image/png).