簡體   English   中英

使用帶有oracle數據庫后端的PHP使用ADOdb庫上傳圖像

[英]Image uploading with php with oracle database backend using ADOdb library

讀取圖像的代碼行是

$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'));

這是我應該將圖像插入數據庫的代碼。

$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));

我從oracle得到的錯誤信息是

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

我知道表模式是這樣的

 Name                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 RECORD_ID                 NOT NULL NUMBER(38)
 IMAGE_ID                  NOT NULL NUMBER(38)
 THUMBNAIL                      BLOB
 REGULAR_SIZE                       BLOB
 FULL_SIZE                      BLOB

我不知道這里有什么問題,我很確定數據庫模式設置正確,$ fileNumber和$ imageNumber是整數,我已經回應了它們並確保它們正在打印正確的數字,在這種情況下, 1001.我也使用oci8驅動程序連接到oracle。 任何人都可以看到這段代碼有什么問題嗎?

在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'); 

所以你需要輸入一個empty_blob(),然后更新它。

根據Glens的回答,使用Oracle 12c,您現在可以通過自動序列更快/自動地完成。

$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); 

編輯:這不是正確的答案,請參閱其他答案。

聽起來它認為$ regular,$ thumb等都是多頭。

根據PHP Oracle FAQ ,插入blob的代碼應如下所示:

$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);

我的猜測是你需要在該特定名稱上設置OCI_B_BLOB。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM