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.