调用Oracle过程时的OCI_INVALID_HANDLE

时间:2015-01-26 11:16:15

标签: php plsql blob email-attachments

我正在尝试编写一个调用oracle过程来发送带附件的电子邮件的PHP函数,我根据此处描述的oracle过程编写了一个oracle过程,使用BLOB作为附件,http://oracle-base.com/articles/misc/email-from-oracle-plsql.php

然而,在调用我的PHP函数时,我得到警告说:

Warning: OCI-Lob::save(): OCI_INVALID_HANDLE in /public_html/classes/oracle.php on line 683

我打电话发送电子邮件的功能是:

public function sendmail_attachment($p_from, $p_to, $p_cc, $p_reply, $p_subject, $p_body, $p_attach_name, $p_attach_mime, $p_attach_blob) {
    $result = '';

    $stid = oci_parse($this->conn, "begin 
                                      send_email_attach (:p1,:p2,:p3,:p4,:p5,:p6,:p7,:p8,:p9); 
                                    end;");

    // Creates an "empty" OCI-Lob object to bind to the locator
    $myLOB = oci_new_descriptor($this->conn, OCI_D_LOB);

    oci_bind_by_name($stid, ':p1', $p_from);
    oci_bind_by_name($stid, ':p2', $p_to);
    oci_bind_by_name($stid, ':p3', $p_cc);
    oci_bind_by_name($stid, ':p4', $p_reply);

    oci_bind_by_name($stid, ':p5', $p_subject);
    oci_bind_by_name($stid, ':p6', $p_body);
    oci_bind_by_name($stid, ':p7', $p_attach_name);
    oci_bind_by_name($stid, ':p8', $p_attach_mime);
    oci_bind_by_name($stid, ':p9', $myLOB, -1, OCI_B_BLOB);

    $contents = file_get_contents($p_attach_blob['tmp_name']);



    // Now save a value to the LOB
    if ( !$myLOB->save($contents) ) {

        // On error, rollback the transaction
        oci_rollback($this->conn);

    } else {

    oci_execute($stid, OCI_NO_AUTO_COMMIT);
        oci_commit($this->conn);
    }

    // Free resources
    oci_free_statement($stid);
    $myLOB->free();
}

由于我已经更改了PL / SQL程序,并且由于隐私,我不会发布该程序包含的内容,但是我将发布关于附加文件的部分

  IF p_attach_name IS NOT NULL THEN
    UTL_SMTP.write_data(l_mail_conn, '--' || l_boundary || UTL_TCP.crlf);
    UTL_SMTP.write_data(l_mail_conn, 'Content-Type: ' || p_attach_mime || '; name="' || p_attach_name || '"' || UTL_TCP.crlf);
    UTL_SMTP.write_data(l_mail_conn, 'Content-Transfer-Encoding: base64' || UTL_TCP.crlf);
    UTL_SMTP.write_data(l_mail_conn, 'Content-Disposition: attachment; filename="' || p_attach_name || '"' || UTL_TCP.crlf || UTL_TCP.crlf);

    FOR i IN 0 .. TRUNC((DBMS_LOB.getlength(p_attach_blob) - 1 )/l_step) LOOP
      UTL_SMTP.write_data(l_mail_conn, UTL_RAW.cast_to_varchar2(UTL_ENCODE.base64_encode(DBMS_LOB.substr(p_attach_blob, l_step, i * l_step + 1))));
    END LOOP;

    UTL_SMTP.write_data(l_mail_conn, UTL_TCP.crlf || UTL_TCP.crlf);
  END IF;

有没有人知道这个问题,如果知道如何解决它将是一个很大的帮助。

0 个答案:

没有答案