PHP 将照片从一个 Oracle 数据库表传输到另一个

发布于 2024-08-25 06:51:18 字数 1834 浏览 9 评论 0原文

我正在尝试跨数据库将一组照片(斑点)从一个表传输到另一个表。除了绑定照片参数之外,我已经快到了。我有以下代码:

$conn_db1 = oci_pconnect('username', 'password', 'db1');
$conn_db2 = oci_pconnect('username', 'password', 'db2');

$parse_db1_select = oci_parse($conn_db1,
"SELECT
    REF PID,
    BINARY_OBJECT PHOTOGRAPH
FROM
    BLOBS");

$parse_db2_insert = oci_parse($conn_db2,
"INSERT INTO
    PHOTOGRAPHS
    (PID,
    PHOTOGRAPH)
VALUES
    (:pid,
    :photo)");    

oci_execute($parse_db1_select);

while ($row = oci_fetch_assoc($parse_db1_select)) {
    $pid = $row['PID'];
    $photo = $row['PHOTOGRAPH'];

    oci_bind_by_name($parse_db2_insert, ':pid', $pid, -1, OCI_B_INT);

    // This line causes an error
    oci_bind_by_name($parse_db2_insert, ':photo', $photo, -1, OCI_B_BLOB);

    oci_execute($parse_db2_insert);
}

oci_close($db1);
oci_close($db2);

但在上面注释的错误行上出现以下错误:

Warning: oci_execute() [function.oci-execute]: ORA-03113: end-of-file on communication channel Process ID: 0 Session ID: 790 Serial number: 118 

有谁知道执行此操作的正确方法吗?

问题已解决

通过一些互联网搜索,我找到了一个可行的解决方案。我将插入 SQL 更改为:

$parse_db2_insert = oci_parse($conn_db2,
"INSERT INTO
    PHOTOGRAPHS
    (P_ID,
    PHOTOGRAPH)
VALUES
    (:pid,
    EMPTY_BLOB())
RETURNING PHOTOGRAPH INTO :photo");

然后将 While 循环更改为:

while ($row = oci_fetch_assoc($parse_db1_select)) {
    $pid = $row['PID'];
    $photo = $row['PHOTOGRAPH'];

    oci_bind_by_name($parse_db2_insert, ':pid', $pid);

    $new_lob = oci_new_descriptor($conn_unite, OCI_D_LOB);
    oci_bind_by_name($parse_db2_insert, ':photo', $new_lob, -1, OCI_B_BLOB);

    oci_execute($parse_db2_insert, OCI_DEFAULT);

    $new_lob->save($photo->load());
    oci_commit($conn_unite);
}

奇怪,但确实如此。

I am attempting to transfer a set of photos (blobs) from one table to another across databases. I'm nearly there, except for binding the photo parameter. I have the following code:

$conn_db1 = oci_pconnect('username', 'password', 'db1');
$conn_db2 = oci_pconnect('username', 'password', 'db2');

$parse_db1_select = oci_parse($conn_db1,
"SELECT
    REF PID,
    BINARY_OBJECT PHOTOGRAPH
FROM
    BLOBS");

$parse_db2_insert = oci_parse($conn_db2,
"INSERT INTO
    PHOTOGRAPHS
    (PID,
    PHOTOGRAPH)
VALUES
    (:pid,
    :photo)");    

oci_execute($parse_db1_select);

while ($row = oci_fetch_assoc($parse_db1_select)) {
    $pid = $row['PID'];
    $photo = $row['PHOTOGRAPH'];

    oci_bind_by_name($parse_db2_insert, ':pid', $pid, -1, OCI_B_INT);

    // This line causes an error
    oci_bind_by_name($parse_db2_insert, ':photo', $photo, -1, OCI_B_BLOB);

    oci_execute($parse_db2_insert);
}

oci_close($db1);
oci_close($db2);

But I get the following error, on the error line commented above:

Warning: oci_execute() [function.oci-execute]: ORA-03113: end-of-file on communication channel Process ID: 0 Session ID: 790 Serial number: 118 

Does anyone know the right way to do this?

Problem Solved

With a bit of internet searching I found a working solution. I changed the insert SQL to:

$parse_db2_insert = oci_parse($conn_db2,
"INSERT INTO
    PHOTOGRAPHS
    (P_ID,
    PHOTOGRAPH)
VALUES
    (:pid,
    EMPTY_BLOB())
RETURNING PHOTOGRAPH INTO :photo");

Then changed the While loop thus:

while ($row = oci_fetch_assoc($parse_db1_select)) {
    $pid = $row['PID'];
    $photo = $row['PHOTOGRAPH'];

    oci_bind_by_name($parse_db2_insert, ':pid', $pid);

    $new_lob = oci_new_descriptor($conn_unite, OCI_D_LOB);
    oci_bind_by_name($parse_db2_insert, ':photo', $new_lob, -1, OCI_B_BLOB);

    oci_execute($parse_db2_insert, OCI_DEFAULT);

    $new_lob->save($photo->load());
    oci_commit($conn_unite);
}

Peculiar, but true.

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

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

发布评论

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

评论(2

尽揽少女心 2024-09-01 06:51:18
oci_bind_by_name($parse_db_insert, ':photo', $photo, -1, OCI_B_BLOB);

您尚未定义 $parse_db_insert 变量。

我想这只是这个错误。

第 2 部分

当连接已建立但随后像超时一样失败时,会返回此 ORACLE 错误(完整说明如下:http://www.dba-oracle.com/m_ora_03113_end_of_file_on_communications_channel.htm)

首先,您确定 $pid 和 $photo 这两个变量包含实际值吗?
其次,在 PHP 手册中的 oci_bind_by_name 下指出:

绑定调用告诉 Oracle 哪个内存
从中读取数据的地址。对于印度
绑定该地址需要包含
oci_execute() 时的有效数据
叫。这意味着变量
界限必须保留在范围内,直到
执行。如果没有的话,出乎意料
结果或错误,例如“ORA-01460:
未实施或不合理
可能会发生“请求转换”。对于
OUT 绑定一种症状没有价值
在 PHP 变量中设置。

全文如下: http://php.net/manual/ en/function.oci-bind-by-name.php

也许您只是绑定错误或者您的变量为空。

oci_bind_by_name($parse_db_insert, ':photo', $photo, -1, OCI_B_BLOB);

You haven't defined a $parse_db_insert variable.

I guess it's just this mistake.

PART 2

This ORACLE error is returned when the connection has been established but then failed like in a timeout (full explanation here: http://www.dba-oracle.com/m_ora_03113_end_of_file_on_communications_channel.htm)

First, are you sure the two variables $pid and $photo contain actual values?
Second, in the PHP manual under oci_bind_by_name states that:

A bind call tells Oracle which memory
address to read data from. For IN
binds that address needs to contain
valid data when oci_execute() is
called. This means that the variable
bound must remain in scope until
execution. If it doesn't, unexpected
results or errors such as "ORA-01460:
unimplemented or unreasonable
conversion requested" may occur. For
OUT binds one symptom is no value
being set in the PHP variable.

Full text here: http://php.net/manual/en/function.oci-bind-by-name.php

Maybe you just got the binding wrong or your variable is empty.

苦笑流年记忆 2024-09-01 06:51:18

否 - 错误来自以下行。

您不会检查之前的 oci 调用以查看它们是否返回了有效结果 - 如果连接失败或超时,您将在此处收到此错误。

No - the error comes from the following line.

You don't check your previous oci calls to see if they returned a valid result - you'll get this error here if the connection failed or timed out.

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