无法将图像存储在BLOB中

时间:2019-07-12 07:23:29

标签: php oracle oracle12c

我正在尝试使用php和oracle 12c将图像存储到数据库中,但不允许我插入没有错误

ORDER_ID                                  NOT NULL NUMBER(38)
RX_IMAGE1                                 NULL BLOB
RX_IMAGE3                                 NULL BLOB
RX_IMAGE4                                 NULL BLOB
CREATE_DATE_TIME                          NULL DATE
LAST_UPDATE_DATE_TIME                     NULL DATE
RX_IMAGE2                                 NULL BLOB
public function prc()
{
    if ($this->input->post('send_prescription') == 'send_prescription') {
        $prescriptionInfo['rx_image1'] = addslashes(file_get_contents($_FILES['pic']['tmp_name']));
        $result = $this->PatientModel->setPrescription($prescriptionInfo);
        if ($result == TRUE) {
            $this->session->set_flashdata('new_val', '1');
        } else {
            $this->session->set_flashdata('new_val', '0');
        }
    }
    $customer_id = $this->session->userdata('CUSTOMER_ID');
    $data['patient_data'] = $this->PatientModel->getPatientsByCustid($customer_id);
    $this->load->view('prescription/new_prescription', $data);
}

没有给出任何错误

1 个答案:

答案 0 :(得分:1)

普通INSERT INTO不适用于BLOB插入。您必须使用标准方法。在下面的代码示例中仔细观察。

CREATE TABLE t (id NUMBER, img BLOB);   
INSERT INTO t VALUES (1, EMPTY_BLOB()); --A simple blob to test

目录

CREATE OR REPLACE DIRECTORY MY_DIR AS '/tmp/images';
GRANT READ, WRITE ON DIRECTORY MY_DIR TO user_name;

要插入的代码

DECLARE
  src_lob  BFILE := BFILENAME('MY_DIR', 'keyboard.jpg'); 
      --MY_DIR refers to the directory in the server where your blob files are stored.
     --It should have been created and relevant permissions be given to your schema 
     --as shown above.
  dest_lob BLOB;
BEGIN
  INSERT INTO t VALUES(2, EMPTY_BLOB())
     RETURNING img INTO dest_lob;

  DBMS_LOB.OPEN(src_lob, DBMS_LOB.LOB_READONLY);
  DBMS_LOB.LoadFromFile( DEST_LOB => dest_lob,
                         SRC_LOB  => src_lob,
                         AMOUNT   => DBMS_LOB.GETLENGTH(src_lob) );
  DBMS_LOB.CLOSE(src_lob);

  COMMIT;
END;
/

对于PHP,请参阅《 PHP开发人员指南》中的this documentation,该指南基本上说明了使用上述技术所需的代码/步骤。

相关问题