使用PHP将图像作为BLOB上传到Oracle中

Shu*_*ini 7 php oracle upload blob

任何人都可以告诉我如何使用PHP将图像作为BLOB存储在oracle数据库中?

一个工作的例子会很好.谢谢.

DRi*_*FTy 14

首先需要获取从$_FILES#global数组上传的图像:

$image = file_get_contents($_FILES['image_field_name']['tmp_name']);
Run Code Online (Sandbox Code Playgroud)

然后在数据库中插入图像试试这个:

$sql = "INSERT INTO table (id, image) VALUES(1, empty_blob()) RETURNING image INTO :image";

$result = oci_parse($connection, $sql);
$blob = oci_new_descriptor($connection, OCI_D_LOB);
oci_bind_by_name($result, ":image", $blob, -1, OCI_B_BLOB);
oci_execute($result, OCI_DEFAULT) or die ("Unable to execute query");

if(!$blob->save($image)) {
    oci_rollback($connection);
}
else {
    oci_commit($connection);
}

oci_free_statement($result);
$blob->free();
Run Code Online (Sandbox Code Playgroud)