使用ADOdb库通过oracle数据库后端使用php上传图像

发布于 2024-10-29 04:01:45 字数 1270 浏览 0 评论 0原文

读取图像的代码行是

$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。谁能看出这段代码有什么问题吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

风柔一江水 2024-11-05 04:01:45

在 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(),然后更新它。

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.

满地尘埃落定 2024-11-05 04:01:45

编辑:这不是正确的答案,请参阅其他答案。

听起来它认为 $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。

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.

预谋 2024-11-05 04:01:45

根据 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); 

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); 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文