P. 1
The Underground PHP and Oracle Manual

The Underground PHP and Oracle Manual

|Views: 38|Likes:
Published by silviupirvu

More info:

Published by: silviupirvu on Nov 18, 2010
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

11/07/2011

pdf

text

original

Temporary LOBs make some operations easier. Inserting data with a Temporary LOB does not use a
RETURNING INTO clause:

Script 70: tempblobinsert.php

$c = oci_connect('hr', 'hrpwd', 'localhost/XE');

$myblobid = 124;
$myv = 'a very large amount of binary data';

$s = oci_parse($c, 'insert into mybtab (blobid, blobdata)
values (:myblobid, :blobdata)');
$lob = oci_new_descriptor($c, OCI_D_LOB);
oci_bind_by_name($s, ':myblobid', $myblobid);
oci_bind_by_name($s, ':blobdata', $lob, -1, OCI_B_BLOB);
$lob->writeTemporary($myv, OCI_TEMP_BLOB);
oci_execute($s, OCI_DEFAULT);
oci_commit($c);
$lob->close(); // close lob descriptor to free resources

?>

Temporary LOBs also simplify updating values:

$s = oci_parse($c, 'update mybtab set blobdata = :bd where blobid = :bid');

If you want to either insert a new row or update existing data if the row turns out to exist already, the SQL
statement can be changed to use an anonymous block :

$s = oci_parse($c,
'begin'

. ' insert into mybtab (blobdata, blobid) values(:blobdata, :myblobid);'
. ' exception'
. ' when dup_val_on_index then'

195

Using Large Objects in OCI8

. ' update mybtab set blobdata = :blobdata where blobid = :myblobid;'
. 'end;');

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->