Oracle Query插入空Blob

时间:2015-11-07 07:25:42

标签: php oracle blob

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

$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大小。

我应该用什么来修改我的查询?

1 个答案:

答案 0 :(得分:1)

好的,我通过改变代码得到了它。

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