Oracle BLOB & PHP
am 23.05.2007 14:33:02 von Alf C Stockton
Can someone suggest a method whereby one retrieves an Oracle BLOB &
subsequently display same on a HTML page?
If possible an example would be great.
--
Regards,
Alf Stockton www.stockton.co.za
Don't plan any hasty moves. You'll be evicted soon anyway.
My email disclaimer is available at www.stockton.co.za/disclaimer.html
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
RE: Oracle BLOB & PHP
am 23.05.2007 16:59:46 von N.A.Morgan
Alf,
This is an exerpt from a paper "Making efficient use of Oracle8i thru
Apache and PHP 4, Thies C. Arntzen 2001" describing
PHP and Oracle LOBs. You should be able to port the code to PHP5
relatively easily.
Regards,
Neil Morgan
large objects
=============3D
PHP has full support for using internal and external LOBs in
oracle. LOBs
are different from "normal" data-types as they require extra
programming on
the script side. when you need to store large amount of data in
one field
LOBs are the ideal choice. you could also store bigger fields
(up to 2GB)
in a "LONG" or "LONG RAW" field (which is as good supported be
PHP) but
oracle plans to drop support for those types in future releases.
"LONG"
and "LONG RAW" fields can not be replicated across servers and
they will
always get loaded into memory when the row containing the "LONG"
or "LONG
RAW" is touched. LOBs don't have this limitation but cause a
tiny bit more
headache when used. oracle has CLOBs (character-LOB) BLOBs
(binary-LOB)
and BFILEs (external files - only path to file is stored in
database).
before you can use a LOB oracle needs to create it - lets
illustrate:
=09
blobdemo.sql
create table blobdemo (id number, lob blob);
$data =3D
array("/lib/libc-2.2.2.so","/lib/libncurses.so.5.2");
$db =3D OCILogon("scott","tiger");
$stmt =3D OCIParse($db,"insert into blobdemo values
=09
(myid.nextval,EMPTY_BLOB()) returning id,lob into :id,:lob");=20
$lob =3D OCINewDescriptor($db);
OCIBindByName($stmt,":ID",$id,32);
OCIBindByName($stmt,":LOB",$lob,-1,SQLT_BLOB);
while (list(,$file) =3D each($data)) {
OCIExecute($stmt,OCI_DEFAULT);
// we cannot use autocommitt here
$lob->save(`cat $file`);
echo "$file id:$id\n";
OCICommit($db);
}
?>
now we have loaded our libc and ncurses into oracle - makes
sense;-)
getting them back is more trivial:
=20
$db =3D OCILogon("scott","tiger");
$stmt =3D OCIParse($db,"select * from blobdemo");
OCIExecute($stmt);
while (OCIFetchInto($stmt,$arr,OCI_ASSOC)) {
echo "id: ".$arr[ "ID" ]."\n";
echo "size: ".strlen($arr[ "LOB"
]->load())."\n";
}
?>
to update a lob you have to load the LOB-descriptor first:
=20
$db =3D OCILogon("scott","tiger");
$stmt =3D OCIParse($db,"select blob from blobdemo for update");
OCIExecute($stmt,OCI_DEFAULT);
while (OCIFetchInto($stmt,$arr,OCI_ASSOC)) {
$content =3D $arr[ "LOB" ]->load();
echo "id: ".$arr[ "ID" ]."\n";
echo "size: ".strlen($content)."\n";
$lob->save(strrev($content));
}
OCICommit($db);
?>
there are functions to just replace a part of a LOB, you can
spool a LOB
to the browser or a file _without_ buffering it a PHP-variable.
the
OCIFetchInto function also allows you to inline the LOB values
into your
result-set, this saves you the call to ->load() but LOB-data
which is
returned instead of the locator can not be modified like shown
above.
the oracle-BFILE type can be read like a normal LOB/CLOB but
can't be
written to. basically you can store the path to a file on the
oracle-server in a table-field and the LOB functions allow you
to read this
file thru the oracle server-connection. this can be extremely
helpful if
your web-server is in front of a firewall and you only want to
allow
oracle-traffic thru this firewall (no NFS-traffic). the BFILE
allows you
to keep your images in the file-system so they don't clutter
your
table-space but you can still access them as if they were a part
of your
database!
-----Original Message-----
From: Alf Stockton [mailto:alf@stockton.co.za]=20
Sent: 23 May 2007 13:33
To: php windows
Subject: [PHP-WIN] Oracle BLOB & PHP
Can someone suggest a method whereby one retrieves an Oracle BLOB &
subsequently display same on a HTML page?
If possible an example would be great.
--
Regards,
Alf Stockton www.stockton.co.za
Don't plan any hasty moves. You'll be evicted soon anyway.
My email disclaimer is available at www.stockton.co.za/disclaimer.html
--
PHP Windows Mailing List (http://www.php.net/) To unsubscribe, visit:
http://www.php.net/unsub.php
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php