Image 使用Codeigniter在Oracle BLOB中插入图像时出错

Image 使用Codeigniter在Oracle BLOB中插入图像时出错,image,oracle,codeigniter,blob,Image,Oracle,Codeigniter,Blob,我正在尝试使用Codeigniter框架和BLOB数据类型将图像插入oracle数据库。但是,我尝试的每件事都会给我以下两个错误: 遇到一个PHP错误 严重性:警告 消息:oci_parse():ORA-00972:标识符太长 文件名:oci8/oci8_driver.php 遇到一个PHP错误 严重性:警告 消息:oci_set_prefetch()期望参数1是给定的资源布尔值 文件名:oci8/oci8_driver.php 这是我的数据库表: CREATE TABLE photos (

我正在尝试使用Codeigniter框架和BLOB数据类型将图像插入oracle数据库。但是,我尝试的每件事都会给我以下两个错误:

遇到一个PHP错误 严重性:警告 消息:oci_parse():ORA-00972:标识符太长 文件名:oci8/oci8_driver.php

遇到一个PHP错误 严重性:警告 消息:oci_set_prefetch()期望参数1是给定的资源布尔值 文件名:oci8/oci8_driver.php

这是我的数据库表:

CREATE TABLE photos (
   id    int,
   photo blob
);
我的控制器功能:

function do_upload() {
    $config['upload_path'] = './uploads/';
    $config['allowed_types'] = 'gif|jpg|png';

    $this->load->library('upload', $config);

     if ( $this->upload->do_upload() ){
         $upload_data = $this->upload->data();
         $this->upload_model->upload_photo($upload_data['full_path']);
     }
     else {
         echo $this->upload->display_errors();
     }
}
public function upload_photo($full_path) {   
    $fp = fopen($full_path, 'r'); 
    $image  = fread($fp, filesize($full_path)); 
    fclose($fp); 

    $sql = "INSERT INTO images ('id', 'photo')
             VALUES ('45', '" . $image . "')";
    $this->db->query($sql);
}
我的模型功能:

function do_upload() {
    $config['upload_path'] = './uploads/';
    $config['allowed_types'] = 'gif|jpg|png';

    $this->load->library('upload', $config);

     if ( $this->upload->do_upload() ){
         $upload_data = $this->upload->data();
         $this->upload_model->upload_photo($upload_data['full_path']);
     }
     else {
         echo $this->upload->display_errors();
     }
}
public function upload_photo($full_path) {   
    $fp = fopen($full_path, 'r'); 
    $image  = fread($fp, filesize($full_path)); 
    fclose($fp); 

    $sql = "INSERT INTO images ('id', 'photo')
             VALUES ('45', '" . $image . "')";
    $this->db->query($sql);
}

数据类型中的问题使用LONGBLOB代替BLOB

CREATE TABLE photos (
   id    int,
   photo longblob
);

在PHP中处理Oracle LOB比处理简单的数据类型要复杂一些。首先,您需要创建一个特定类型的新OCI描述符,然后在SQL语句中使用它。有关详细信息,请参阅此链接:

下面是php.net中的简单代码示例:

<?php
/* This script demonstrates file upload to LOB columns
 * The formfield used for this example looks like this
 * <form action="upload.php" method="post" enctype="multipart/form-data">
 * <input type="file" name="lob_upload" />
 * ...
 */
  if (!isset($lob_upload) || $lob_upload == 'none'){
?>
<form action="upload.php" method="post" enctype="multipart/form-data">
Upload file: <input type="file" name="lob_upload" /><br />
<input type="submit" value="Upload" /> - <input type="reset" value="Reset" />
</form>
<?php
  } else {

     // $lob_upload contains the temporary filename of the uploaded file

     // see also the features section on file upload,
     // if you would like to use secure uploads

     $conn = oci_connect($user, $password);
     $lob = oci_new_descriptor($conn, OCI_D_LOB);
     $stmt = oci_parse($conn, "insert into $table (id, the_blob)
               values(my_seq.NEXTVAL, EMPTY_BLOB()) returning the_blob into :the_blob");
     oci_bind_by_name($stmt, ':the_blob', $lob, -1, OCI_B_BLOB);
     oci_execute($stmt, OCI_DEFAULT);
     if ($lob->savefile($lob_upload)){
        oci_commit($conn);
        echo "Blob successfully uploaded\n";
     }else{
        echo "Couldn't upload Blob\n";
     }
     $lob->free();
     oci_free_statement($stmt);
     oci_close($conn);
  }
?>

上传文件:
-