PHP: ibase_blob_get - Manual

downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

ibase_blob_import ibase_blob_echo

Last updated: Sat, 27 Jan 2007

view this page in

# ibase_blob_get

(PHP 3 >= 3.0.7, PHP 4, PHP 5)

ibase_blob_get -- Get len bytes data from open blob

## Description

string ibase_blob_get ( resource blob_handle, int len )

This function returns at most `len` bytes from a BLOB that has been opened for reading by ibase_blob_open(). Returns `FALSE` on failure.

`<?php
$sql = "SELECT blob_value FROM table";
$result = ibase_query($sql);
$data = ibase_fetch_object($result);
$blob_data = ibase_blob_info($data->BLOB_VALUE);
$blob_hndl = ibase_blob_open($data->BLOB_VALUE);
echo ibase_blob_get($blob_hndl, $blob_data[0]);
?>`

Whilst this example doesn't do much more than a 'ibase_blob_echo($data->BLOB_VALUE)' would do, it does show you how to get information into a $variable to manipulate as you please.

> Замечание: It is not possible to read from a BLOB that has been opened for writing by ibase_blob_create().

See also ibase_blob_open(), ibase_blob_close() and ibase_blob_echo().

add a note User Contributed Notes
ibase_blob_get
trinite at trinite dot mine dot nu
29-Dec-2005 03:33
`The ways mentioned above won't work with segmented blobs. To fix this, I use the following:
(btw, $result->MFOTO is an image in the database)
<?php
$result = ibase_fetch_object($result);
/*
ibase_blob_info array:
[0] bloblength(total)
[1] number of segments
[2] size of largest segment
[3] stream or segmented blob
[4] ??
*/
$blobinfo = ibase_blob_info($result->MFOTO);
$blobhandle = ibase_blob_open($result->MFOTO);
for($i = 0; $i < $blobinfo[1]; $i++){
$readsize = $blobinfo[2];
if($i == ($blobinfo[1] - 1)){
$readsize = $blobinfo[0] - (($blobinfo[1] - 1) * $blobinfo[2]);
}
$totalimage .= ibase_blob_get($blobhandle, $readsize);
}
ibase_blob_close($blobhandle);
echo $totalimage;
?>
This should do the trick ;)`
hamacker
24-Nov-2004 06:03
`The first example is wrong, is missing ibase_blob_close() function.
The correct example is :
<?php
$sql = "SELECT blob_value FROM table";
$result = ibase_query($sql);
$data = ibase_fetch_object($result);
$blob_data = ibase_blob_info($data->BLOB_VALUE);
$blob_hndl = ibase_blob_open($data->BLOB_VALUE);
print ibase_blob_get($blob_hndl, $blob_data[0]);
// without close blob conection, php and ibase_blob_get() do not run.
ibase_blob_close($blob_hndl);
?>`
sol at nospam dot example dot com
18-Mar-2003 10:59
`I found examples like these:
$sql = "SELECT ID, CONTENTTYPE, BLOBSIZE, DATA,NAME ";
$sql.= " FROM OM_BLOB WHERE ID = 42";
$result = ibase_query($sql);
while ($row=ibase_fetch_object($result))
{
$blob_data = ibase_blob_info( $row->DATA);
$blob_hndl = ibase_blob_open($row->DATA);
$image = ibase_blob_get( $blob_hndl, $blob_data[0]);
}
but this won't work for large blobs.
One solution for big blobs is to retrieve them by chunks:
$sql = "SELECT ID, CONTENTTYPE, BLOBSIZE, DATA,NAME ";
$sql.= " FROM OM_BLOB WHERE ID = 42";
$result = ibase_query($sql);
while ($row=ibase_fetch_object($result))
{
$image = ibase_blob_get($blob_hndl,8192);
while($data = ibase_blob_get($blob_hndl, 8192)){
$image .= $data;
}
}`
add a note
ibase_blob_import ibase_blob_echo

Last updated: Sat, 27 Jan 2007
show source | credits | stats | sitemap | contact | advertising | mirror sites
Copyright © 2001-2007 The PHP Group
All rights reserved.
This mirror generously provided by: Yahoo! Inc.
Last updated: Sat Mar 10 09:32:46 2007 PST