2015-11-07 145 views
1

我想在表格的Blob列中插入文本文件。我正在使用PHP。 我使用的查詢是:Oracle查詢插入空Blob

$qry = "INSERT INTO blobTable(date_input,file_name,blob_CONTENT) VALUES (SYSDATE,'$fileName',empty_blob()) RETURNING blob_CONTENT INTO :blob_CONTENT"; 
$stmt = OCIparse($conn,$qry); 
$blob = ocinewdescriptor($conn, OCI_D_LOB); 
ocibindbyname($stmt, ":Blob_CONTENT", $blob, -1, OCI_B_BLOB); 
ociexecute($stmt); 
$result = oci_num_rows($stmt); 
ocicommit($conn); 
ocifreestatement($stmt); 
$blob->free(); 

而是將其插入該表是空BLOB。我也嘗試過utl_raw.cast_to_raw,但它有2K的限制,但我的文件預計大於10M。

我該怎麼修改我的查詢?

+0

爲什麼mysql ?????? –

回答

0

好吧我通過改變代碼的工作得到了它的工作。

$tmpName = $_FILES['datafile']['tmp_name']; //Temporary name of my file 
$qry = "INSERT INTO fileTable(date_input,file_name,file_CONTENT) VALUES (SYSDATE,'$fileName',empty_blob()) RETURNING file_CONTENT INTO :file_CONTENT"; 
$stmt = OCIparse($conn,$qry); 
$blob = ocinewdescriptor($conn, OCI_D_LOB); 
ocibindbyname($stmt, ":file_CONTENT", $blob, -1, OCI_B_BLOB); 
ociexecute($stmt, OCI_DEFAULT); 
if ($blob->savefile($tmpName)){ 
//Missed this step initially. 
    oci_commit($conn); 
    echo "Blob successfully uploaded\n"; 
} 
else 

{ 
    echo "Couldn't upload Blob\n"; 
} 
$result = oci_num_rows($stmt); 
ocicommit($conn); 
ocifreestatement($stmt); 
$blob->free();