Abdunnasir K P
Abdunnasir K P

Reputation: 117

Display Blob content after fetching from firebird db

When I run the below query

select first 1 IMG from img_lib;

I get the output as IMG 4cc:0 BLOB display set to subtype 1. This BLOB: subtype = 0

Can any one help me with a PHP code to display the blob content as an Image? I don't think MySQL will work here, Can anyone help me with firebird query?

Upvotes: 0

Views: 1418

Answers (1)

Marcodor
Marcodor

Reputation: 5741

PHP offers two libraries to work with Firebird/Interbase databases: Ibase & PDO.

Ibase offer two ways to retrieve blobs. One is using lazy loading with ibase_blob_get function:

if (is_null($field)) return null;
$info = ibase_blob_info($field);
$handle = ibase_blob_open($field);
return ibase_blob_get($handle, $info[0]);

This way is good, when you need to fetch just some blobs, not all, as it is a costly operation.

Another way is to use IBASE_TEXT fetch flag parameter in ibase_fetch_assoc function or fetch object / row. It will return right in fetch result the blob content.

The second library, PDO with Firebird driver, fetches blobs automatically.

Next after you have loaded BLOB content into memory, you need to output it as an image. Here is a sample code, assuming you have a jpeg image format:

<?php
// fetch here blob content described in previous methods
header('Content-Type: image/jpeg');
echo $blob_content;

Later point image source to your script like <img src="blob_image.php" />

Upvotes: 2

Related Questions