php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #27083 binding blobs to procedure params corrupts them
Submitted: 2004-01-29 06:29 UTC Modified: 2004-09-17 14:48 UTC
From: ceco at noxis dot net Assigned: tony2001 (profile)
Status: Closed Package: Documentation problem
PHP Version: 4.3.4 OS: windows 2000 server
Private report: No CVE-ID: None
 [2004-01-29 06:29 UTC] ceco at noxis dot net
Description:
------------
first of all I should say that it may be documentation problem, because didn't find good documentation of the LOB object 

i have a oracle procedure, which accepts BLOB

(see the code below)

it inputs the data in the blob but when i extract (with the oracle tools or with other php script) it is corrupted it is exactly 2 times larger
when everything is changed to clob (of course the data is text not jpg), this function work ok

also it is workig for me if I use insert into (the_blob) values (empty_blob()) returning the_blob into :the_blob

and then bind $lob and use $lob->save

but i don't want to have this

I think $lob->WriteTemporary mangles the data somehow and corrupts it

Reproduce code:
---------------
	include_once 'config/environment.inc.php';

	$fd = fopen('Sample.jpg', 'r');
	$data = fread($fd, filesize('Sample.jpg'));
	fclose($fd);

	$conn = ocilogon($CFG_DB['username'], $CFG_DB['password'], $CFG_DB['db']);
	$lob = OCINewDescriptor($conn, OCI_D_LOB);

	$stmt = OCIParse($conn,"begin TEST_PROC(:the_blob); end;");
	OCIBindByName($stmt, ':the_blob', &$lob, -1, OCI_B_BLOB);
	$lob->WriteTemporary($data);
	OCIExecute($stmt, OCI_DEFAULT);
	$lob->close();
	$lob->free();
	OCICommit($conn);


create procedure TEST_PROC(the_blob blob) is
begin
insert into test_table values (the_blob);
end;

create table test_table (the_blob blob);


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-01-29 09:21 UTC] tony2001@php.net
Don't use writeTemporary, it's not intended for writing persistent LOB's.
You should use save() or you can upgrade to PHP5 and use $lob->write() method.
 [2004-01-29 11:16 UTC] ceco at noxis dot net
in examle 2 on http://www.php.net/manual/en/function.ocinewdescriptor.php

it is used exactly like that, only it is clob

I cannot use php 5, I made workaround converting blob to hex, sending it as clob and then reconverting it to binary ;-))
a little strange and cpu intensive but works and since it is not very often used I'll have to leave it that way
 [2004-01-29 11:46 UTC] tony2001@php.net
ok, I'll take a look at it soon.
 [2004-02-04 03:55 UTC] tony2001@php.net
In php 4.3.x method writeTemporary() doesn't accept second parameter, which exists only in php5 branch.
This parameter should be used to tell method wich type of Lob you're trying to write.
Thus, in php4.3.x writeTemporary always tries to create CLOB, and you're using it to write BLOB.
The example in docs should be changed, I'm working on new docs atm.
 [2004-02-04 05:37 UTC] ceco at noxis dot net
ok i'll leave it that way, but just a suggestion for the new version

isn't it strange to make method WriteTemporary to accept second param, which explicitly tells the object, which type of instance it is?

can't it be done when binding it (OCIBindByName) to something to change the type of object so it knows what it is bound to (blob,clob or whatever),
or when created to tell it the type OCINewDescriptor with the last param
 [2004-05-22 11:42 UTC] nlopess@php.net
Hi Antony!

Is this already solved in the new docs?
 [2004-09-17 14:48 UTC] vrana@php.net
There's no writeTemporary in the example, so this one is probably solved.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Sep 06 07:00:01 2025 UTC