Getting blobs out of Oracle
| From: | David Newcomb | Date: | Fri, 23 Jun 2000 10:56:51 +0000 |
| Subject: | Getting blobs out of Oracle | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-588@lists.php.net to get a copy of this message | ||
Hi there,
Having a bit of trouble with getting BLOBs out of Oracle 8, and was
wandering if
anyone has managed to do it. Does it sound familiar?
I have had a try but there is so little documentation in this area that
I am going around in circles and confusing myself. Could someone
give me a hand, please?
Given an Oracle table:
create table upload (
id number(10),
the_blob blob );
<?php
// Download
/* This script demonstrates file download to LOB columns
* The formfield used for this example looks like this
*/
if(!isset($lob_download) || $lob_upload == 'none'){
?>
<form action="<?php echo $PHP_SELF; ?>" method="get">
Download id: <input type="text" name="lob_download"><br>
<input type="submit" value="Download"> - <input
type="reset">
</form>
<?php
}
else
{
echo "<PRE>\n";
$conn = OCILogon("webdb", "webdb");
$stmt = OCIParse($conn,"select the_blob from upload where id =
$lob_download");
$lob = OCINewDescriptor($conn, OCI_D_LOB);
OCIDefineByName($stmt,"the_blob",&$lob);
OCIExecute($stmt, OCI_DEFAULT);
OCIFetch($stmt);
$bob = OCIResult($stmt,"THE_BLOB");
echo "bob=|$bob|<BR>\n";
list($key,$val) = each($bob);
echo "key=|$key|<br>\n";
echo "val=|$val|<p>\n\n";
$l = $lob;
$l = $lob;
$len = strlen($lob);
list($key,$val) = each($lob);
echo "key=|$key|<br>\n";
echo "val=|$val|<p>\n\n";
echo "len=|$len|<BR>\n";
echo "lob=|$lob|<BR>\n";
echo "l=|$l|<p>\n\n";
$lob->free();
OCIFreeStatement($stmt);
OCILogoff($conn);
list($key,$val) = each($lob);
echo "key=|$key|<br>\n";
echo "val=|$val|<p>\n\n";
echo "lob=|$lob|<BR>\n";
echo "l=|$l|<p>\n";
echo "</PRE>\n";
}
?>
Produces the results:
bob=|Object|
key=|descriptor|
val=|Resource id #6|
key=|descriptor|
val=|Resource id #5|
len=|6|
lob=|Object|
l=|Object|
key=||
val=||
lob=|Object|
l=|Object|
Any help would be greatly appreciated.
David.