Subject | Re: [firebird-support] SP, BLOB, PHP |
---|---|
Author | Daniela Mariaschi |
Post date | 2003-06-30T10:14:19Z |
> have anybody a little example for usig blobs in stored procedures?Hi Frank
> The blob is a parameter of the sp and comes from php.
> The sp must insert this blob in a table (subtype 0 segment size 80).
>
hope this could be useful
Regards
Daniela
=========================================================================
DDL
=========================================================================
CREATE TABLE MY_TABLE (
ID INTEGER NOT NULL,
MY_BLOB BLOB SUB_TYPE 0 SEGMENT SIZE 80);
CREATE PROCEDURE MY_TABLE_BLOB_INSERT (
DATA BLOB SUB_TYPE 0 SEGMENT SIZE 80)
RETURNS (
ID INTEGER)
AS
begin
ID = GEN_ID(GEN_MY_TABLE_ID, 1);
insert into my_table (id,my_blob)
values (:id,:data );
suspend;
end
=========================================================================
SCRIPT
=========================================================================
<?
function import_blob($conn, $q_str, $filename){
$err = '';
$id_blob_inserted = -1;
$fd = fopen($filename, 'rb'); // test for fopen would be better
if ($blob_id_str = ibase_blob_import($conn, $fd)) {
$err .= ibase_errmsg();
$res = ibase_query($conn, $q_str , $blob_id_str);
$err .= ibase_errmsg();
if (empty($err)) {
$row = ibase_fetch_row($res); // retrive id auto_number
$id_blob_inserted = $row[0];
ibase_commit($conn);
}else{
echo "<br>Error found : $err [trans rollback]";
ibase_rollback($conn);
}
}
fclose($fd);
return($id_blob_inserted);
}
$conn = ibase_connect('localhost:/opt/interbase/db/test.gdb', 'test',
'test', NULL, NULL, 3);
echo "blob inserted with id = " . import_blob($conn,
'select * from MY_TABLE_BLOB_INSERT (?)', 'test.png');
?>
=======================================================
END SCRIPT
=======================================================