我试图直接将图像插入到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());
}
?>
答案 0 :(得分:0)
我终于做到了:
<?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();