【问题标题】:pdo insert image into oracle database directly - inserting BLOB - 0Bpdo 将图像直接插入 oracle 数据库 - 插入 BLOB - 0B
【发布时间】:2017-03-23 14:03:31
【问题描述】:

我正在尝试将图像直接插入到 oracle 数据库表中。在我的数据库中,我总是得到 [BLOB - 0B]。它不会将图像插入表中。我也没有收到任何错误。

<html>
<form action="save_img.php" method="post" enctype="multipart/form-data">
     <input type="file" name="image"/>
      <input type="submit"/>
</form>
</html>


<?php
include('config.php');

$fp = fopen($_FILES['image']['tmp_name'],'rb'); //read binary

try{         
     $stmt=$con->prepare("insert into images(photo) values(?)");    
     $stmt->bindParam(1,$fp,PDO::PARAM_LOB);
     $con->errorInfo();
     $stmt->execute();
}

catch(PDOEception $e){
    echo($e->getMessage()); 
}

?>

【问题讨论】:

  • 如果您必须将图像放入数据库表中,则在将文件发送到数据库之前base64encode()
  • 当然,读取打开的文件而不是尝试将文件句柄发送到数据库也很有用。跨度>

标签: php html oracle pdo oracle12c


【解决方案1】:

我终于做到了:

<?php

   include '../conexao_oracle.php';

   $db->beginTransaction(); // VERY IMPORTANT !
   $stmt = $db->prepare(
       "INSERT INTO images (photo) ".
       "VALUES (EMPTY_BLOB()) ".
       "RETURNING photo INTO :photo");
   $stmt->bindParam(':photo', $blob, PDO::PARAM_LOB);
   $blob = fopen($_FILES['image']['tmp_name'],'rb');
   $stmt->execute();
   $db->commit();

【讨论】:

    猜你喜欢
    • 2014-07-14
    • 2021-02-17
    • 2020-02-25
    • 2014-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多