Subject [firebird-php] BUG: ibase_blob_get
Author Gerhard Knapp
System:

PHP Version 4.2.2
System Windows NT 5.1 build 2600
Build Date Jul 21 2002 23:51:43
Server API Apache
Virtual Directory Support enabled
Configuration File (php.ini) Path C:\WINDOWS\php.ini
Debug Build no
Thread Safety enabled

Interbase Support enabled
Revision $Revision: 1.77.2.3 $
Dynamic Module yes
Allow Persistent Links Yes
Persistent Links 0/unlimited
Total Links 0/unlimited
Timestamp Format %m/%d/%Y %H:%M:%S
Date Format %m/%d/%Y
Time Format %H:%M:%S

Firbird 1.5 Beta 3

BUG-Description:
I. store blob in db: 65535 kb -> binary jgp picture
(field definition: GRUND_FOTO BLOB SUB_TYPE 0 SEGMENT SIZE 4096)
(note: have tested different SEGMENT SIZE Values, no difference in the bug)

II. Can open this blob in Delphi-Application correct, also with IBExpert

III. Using following php-source:

...............................
$S = "SELECT GRUND_FOTO FROM GSE WHERE GID = $gid";
$Q = ibase_query($S);
$R = ibase_fetch_object($Q);
$BINFO = ibase_blob_info($R->GRUND_FOTO);
//...BINFO[2] shows the size of the Blob, the value here is: 65535,
and this is correct...
if ($BINFO[2] == 0)
{
echo "<tr>
<td width='699' height='1' colspan='3'>
<br>$ausgabe //... other things ....
<CENTER><IMG SRC='platzhalter.gif'></CENTER>
<hr>
</td>
</tr>";
}
else
{
$TEMPFILE = tempnam("./","TMP");
$TEMPFILE .= ".jpg";
$FILEID = fopen($TEMPFILE,"wb");
$BLOBID = ibase_blob_open($R->GRUND_FOTO);

while ($PIC = ibase_blob_get($BLOBID,10240))
{
fputs($FILEID,$PIC);
}
fclose($FILEID);
//..... the resulting filesize = 536 KB and not the same jpf-format
!!!...
ibase_blob_close($BLOBID);
echo "<tr>
<td width='699' height='1' colspan='3'>
<CENTER><IMG SRC=$TEMPFILE ></CENTER>
<hr>
</td>
</tr>";
}
ibase_free_result($Q);
}
ibase_commit();
ibase_close;
}
..................................

BUG: the blobsize information is correct, but not the resulting blobdata!
$PIC should be the complete jpg-picture, as stored in the db, but it isn't
!!!
-> if stored as file it has now: 536 KB instead of 65 KB, and it has another
format,
couldn't be opened with Paint Shop Pro p.e.

discussion:
I tried nearly all what possible, also direct output to the browser,
but this also brings errors:

-> if $PIC will be the correct jpg, then it should be displayed also with
...................................
header("Content-type: image/jpeg");
Imagejpeg($PIC);
...................................
but: wrong format ... comes as error

Questions:
the interbase functions in PHP are very bad documentated ... why?
i have to found some things with try and error methode
PHP-HANDBOOK:
- ibase_blob_info -- Return blob length and other useful info
thats all in the php-handbook ...

what is returnparameter [0]?
what is returnparameter [1]?
what is returnparameter [2] = blobsize, i know now ..

... in some articels i found dubios things, like: IBASE_TEXT, is there
another one like IBASE_BINARY ????

a handfull of functions with very bad descriptons, this is not the
way to make firebird/interbase to a really alternative to others,
BUT I KNOW FIREBIRD IS ONE OF THE BEST!
how we can change this?
who has written the php_interbase.dll for PHP? where i can find
the sourcecode for this dll?
i don't want to develop with C but i can
read this source..


best regards
-Gerhard

(p.s. I have no C++ Compiler from Microsoft, and i don't want it,
i used many languages in my life (Fortran77, VAX-Pascal, ADA, Delphi,
C with Solaris, VBA (i also not want), and for years C++ for Informix
Neweara,
this experience was enough for me with C++ from Microsoft, sorry..)
With Delphi i can all do, what i have to do,
but my job is to develop applications, not systemsoftware)