PHP 将照片从一个 Oracle 数据库表传输到另一个
我正在尝试跨数据库将一组照片(斑点)从一个表传输到另一个表。除了绑定照片参数之外,我已经快到了。我有以下代码:
$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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您尚未定义 $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 下指出:
全文如下: http://php.net/manual/ en/function.oci-bind-by-name.php
也许您只是绑定错误或者您的变量为空。
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:
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.
否 - 错误来自以下行。
您不会检查之前的 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.