ibase_blob_get
(PHP 5)
ibase_blob_get — Get len bytes data from open blob
Описание
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().
Замечание:
It is not possible to read from a BLOB that has been opened for writing by ibase_blob_create().
Список параметров
-
blob_handle
-
A BLOB handle opened with ibase_blob_open().
-
len
-
Size of returned data.
Возвращаемые значения
Returns at most len
bytes from the BLOB, or FALSE
on failure.
Примеры
Пример #1 ibase_blob_get() example
<?php
$result = ibase_query("SELECT blob_value FROM table");
$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]);
?>
Смотрите также
- ibase_blob_open() - Open blob for retrieving data parts
- ibase_blob_close() - Close blob
- ibase_blob_echo() - Output blob contents to browser
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Расширения для работы с базами данных
- Расширения для работы с базами данных отдельных производителей
- Firebird/InterBase
- ibase_add_user
- ibase_affected_rows
- ibase_backup
- ibase_blob_add
- ibase_blob_cancel
- ibase_blob_close
- ibase_blob_create
- ibase_blob_echo
- ibase_blob_get
- ibase_blob_import
- ibase_blob_info
- ibase_blob_open
- ibase_close
- ibase_commit_ret
- ibase_commit
- ibase_connect
- ibase_db_info
- ibase_delete_user
- ibase_drop_db
- ibase_errcode
- ibase_errmsg
- ibase_execute
- ibase_fetch_assoc
- ibase_fetch_object
- ibase_fetch_row
- ibase_field_info
- ibase_free_event_handler
- ibase_free_query
- ibase_free_result
- ibase_gen_id
- ibase_maintain_db
- ibase_modify_user
- ibase_name_result
- ibase_num_fields
- ibase_num_params
- ibase_param_info
- ibase_pconnect
- ibase_prepare
- ibase_query
- ibase_restore
- ibase_rollback_ret
- ibase_rollback
- ibase_server_info
- ibase_service_attach
- ibase_service_detach
- ibase_set_event_handler
- ibase_trans
- ibase_wait_event
Коментарии
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;
}
}
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);
?>
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 ;)