Bug #69552 [Opn->Nab]: PDO INSERT BLOB in oracle 12c database
| From: | sixd@php.net | Date: | Fri, 01 May 2015 17:28:45 +0000 |
| Subject: | Bug #69552 [Opn->Nab]: PDO INSERT BLOB in oracle 12c database | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-192438@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=69552&edit=1
ID: 69552
Updated by: sixd@php.net
Reported by: michael dot lane at fadq dot gouv dot qc dot ca
Summary: PDO INSERT BLOB in oracle 12c database
-Status: Open
+Status: Not a bug
Type: Bug
Package: PDO OCI
Operating System: Debian 3.2.65-
PHP Version: 5.4.40
Block user comment: N
Private report: N
New Comment:
Please post questions on a mail list or forum before logging a bug.
One forum is https://community.oracle.com/community/development_tools/php
Try something like:
function do_insert($db, $id, $data1, $data2)
{
$db->beginTransaction();
$stmt = $db->prepare("insert into mytable (id, data1, data2) values (:id, empty_blob(),
empty_blob()) returning data1, data2 into :blob1, :blob2");
$stmt->bindParam(':id', $id);
$stmt->bindParam(':blob1', $blob1, PDO::PARAM_LOB);
$stmt->bindParam(':blob2', $blob2, PDO::PARAM_LOB);
$blob1 = null;
$blob2 = null;
$stmt->execute();
fwrite($blob1, $data1);
fclose($blob1);
fwrite($blob2, $data2);
fclose($blob2);
$db->commit();
}
Previous Comments:
------------------------------------------------------------------------
[2015-04-30 14:36:51] michael dot lane at fadq dot gouv dot qc dot ca
I forgot in my example the value of the PDO::PARAM_LOB.
$fp = fopen($uploadfile['tmp_name'], 'rb');
$stmt->bindParam(":FILELOB", $fp, PDO::PARAM_LOB);
------------------------------------------------------------------------
[2015-04-30 13:59:46] michael dot lane at fadq dot gouv dot qc dot ca
Description:
------------
I try all possibility but I'm pretty sure it's not possible to insert a file in an Oracle
12C database BLOB with PDO. All the other column have a value but my BLOB data length is always 0.
Table description:
Table: LOCI_DOCU
Column Name id Data type Null?
ID 1 NUMBER (10) N
FK_SH_ID 2 NUMBER (10) N
NOM_PHYS_DOCU 3 VARCHAR2 (150 Byte) N
TIMB_MAJ 4 DATE N
USAG_MAJ 5 VARCHAR2 (12 Byte) N
ADR_DOCU 6 VARCHAR2 (200 Byte) Y
DOCU 7 BLOB Y
TAIL_DOCU 8 NUMBER (13) Y
MIME_TYPE 9 VARCHAR2 (200 Byte) Y
Test script:
---------------
$connection = $this->getConnection();
$sql = "INSERT INTO LOCI_DOCU
(fk_sh_id, nom_phys_docu, tail_docu, mime_type, docu)
VALUES (:FK, :NAMEFILE, :SIZEFILE, :MIMEFILE, EMPTY_BLOB())
RETURNING DOCU INTO :FILELOB";
$stmt = $connection->prepare($sql);
$stmt->bindParam(":FK", 1, PDO::PARAM_INT);
$stmt->bindParam(":NAMEFILE", 'MyFileName.jpg, PDO::PARAM_STR);
$stmt->bindParam(":SIZEFILE", 278743, PDO::PARAM_INT);
$stmt->bindParam(":MIMEFILE", "image/jpeg", PDO::PARAM_STR);
$stmt->bindParam(":FILELOB", 50, PDO::PARAM_LOB);
$stmt->execute();
Expected result:
----------------
Row insert with no error.
Get a data length of 278743 and be able to get the file working if downloaded.
Actual result:
--------------
Row insert with no error.
Data length of 0 of the BLOB in the database.
When downloading file, can not show result of the original inserted file, broken file with no
content.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=69552&edit=1