开发者

Image uploading with php with oracle database backend using ADOdb library

The lines of code that reads the images are

$regular = fread(fopen('tmp/tmp3.jpg', "r"), filesize('tmp/tmp3.jpg'));
$thumb= fread(fopen('tmp/tmp2.jpg', "r"), filesize('tmp/tmp2.jpg'));
$pure = fread(fopen('tmp/tmp.jpg', "r"), filesize('tmp/tmp.jpg'));

This is the code I have that should insert an image into the database.

$q = "INSERT INTO pacs_images VALUES (:record_id, :image_id, :thumb, :regular, :pure)";//debug
$statement = $conn -> Prepare($q);
$rs = $conn -> Execute($statement, array('record_id' => $fileNumber, 'image_id' => $imageNumber,
                    'thumb' => $thumb, 'regular' => $regular, 'pure' => $pure));

The error message I get from oracle is

ORA-01461: can bind a LONG value only for insert into a LONG column

I know for the fact that the table schema is

 Name                      Null?    Type
 ----------------------------------------- -------- -------------开发者_运维百科---------------
 RECORD_ID                 NOT NULL NUMBER(38)
 IMAGE_ID                  NOT NULL NUMBER(38)
 THUMBNAIL                      BLOB
 REGULAR_SIZE                       BLOB
 FULL_SIZE                      BLOB

I don't know what is wrong here, I'm pretty sure the database schema is set up properly and $fileNumber and $imageNumber are integers, and I have echoed them and made sure they are printing the right numbers, in this case, 1001. I'm also using the oci8 driver to connect to oracle. Can anyone see what's wrong with this code?


Found the actual way to do it in ADOdb

UpdateBlob($table,$column,$val,$where)

Allows you to store a blob (in $val) into $table into $column in a row at $where. 
Usage:

# for oracle 
$conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, empty_blob())'); 
$conn->UpdateBlob('blobtable','blobcol',$blobvalue,'id=1'); 

So you need to put in an empty_blob(), and then update it.


EDIT: This is not the right answer, see the other answer.

Sounds like it thinks that $regular, $thumb, etc. are longs.

According to the PHP Oracle FAQ the code to insert a blob should look like:

$lob = oci_new_descriptor($conn, OCI_D_LOB);
$stid = oci_parse($conn, 'INSERT INTO BTAB (BLOBID, BLOBDATA) '
.'VALUES(:MYBLOBID, EMPTY_BLOB()) RETURNING BLOBDATA INTO :BLOBDATA');
oci_bind_by_name($stid, ':MYBLOBID', $myblobid);
oci_bind_by_name($stid, ':BLOBDATA', $lob, -1, OCI_B_BLOB);
oci_execute($stid, OCI_DEFAULT);

My guess is you need the OCI_B_BLOB set on that specific name.


According to Glens answer, with Oracle 12c you can do it now faster/automatic with an Auto Sequence.

$conn->Execute('INSERT INTO blobtable (OBJEKT_ID, blobcol) VALUES (111, empty_blob())'); 
$conn->Execute('SELECT blobtable_SEQ1.CURRVAL FROM DUAL'); // Sequence name, can find it in the SQL Developer
$aresult = $result->_array;
$curID = $aresult[0]['CURRVAL'];
$conn->UpdateBlob('blobtable','blobcol',$blobvalue,'id='.$curID); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜