php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46728 PDO(OCI)::fetchAll with stream (CLOB) : resource contains always same value
Submitted: 2008-12-02 08:56 UTC Modified: 2016-03-08 01:49 UTC
Votes:25
Avg. Score:4.6 ± 0.8
Reproduced:24 of 25 (96.0%)
Same Version:3 (12.5%)
Same OS:14 (58.3%)
From: berlioz at nicematin dot fr Assigned:
Status: No Feedback Package: PDO OCI
PHP Version: 5.2.6 OS: Linux (All ?)
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: berlioz at nicematin dot fr
New email:
PHP Version: OS:

 

 [2008-12-02 08:56 UTC] berlioz at nicematin dot fr
Description:
------------
in PDO_OCI when you retrieve records from a table with a CLOB field using fetchAll(), fetchAll() returns different resource ids but they all contain the same datas from the last record of the set. Other fields are ok.

if you loop with fetch it works fine.



Reproduce code:
---------------
$conn = new PDO("oci:dbname=".$tns,$db_username,$db_password);

$stmt=$conn->query('select * from my_table_with_clob');

$records=$stmt->fetchAll(PDO::FETCH_ASSOC);

print_r($records);

foreach($records as $record)
{
	echo "my_clob=".stream_get_contents($record['MY_CLOB'])."\n";
}

Expected result:
----------------
my_clob=Data from record 0
my_clob=Data from record 1
my_clob=Data from record 2
my_clob=Data from record 3
my_clob=Data from record 4

Actual result:
--------------
my_clob=Data from record 4
my_clob=Data from record 4
my_clob=Data from record 4
my_clob=Data from record 4
my_clob=Data from record 4

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-02-22 04:48 UTC] crescentfreshpot at yahoo dot com
Seems similar to bug #37706 I reported in the oci8 module a while back. All my fetched rows would all point to the
same (last fetched) lob descriptor.

It seems there is no way to stop oci_fetch_all (and presumably PDO_OCI since it uses the same oci.c api) from automatically
fetching lob data and return them as separate, individual streams.
 [2009-02-22 04:50 UTC] crescentfreshpot at yahoo dot com
Sorry, I meant:

It seems there is no way to get oci_fetch_all (and presumably PDO_OCI
since it uses the same oci.c api) return lob data as separate, individual streams.
 [2009-04-25 15:23 UTC] jani@php.net
So is this a bug or not? If it's a missing feature, please change the 
category. If this is bug and still exists in PHP 5.2.9, please update 
the version field.
 [2009-05-03 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2016-03-08 01:49 UTC] sixd@php.net
-Package: PDO related +Package: PDO OCI
 [2017-01-12 07:40 UTC] anatoly dot rugalev at gmail dot com
This bug still exist in PHP 5.6.26

Workaround:

$result = [];
while ($row = $this->pdoStatement->fetch($fetchMode)) {
    foreach ($row as $name => $value) {
        if (is_resource($value)) {
            $row[$name] = stream_get_contents($value);
        }
    }
    $result[] = $row;
}
 [2020-03-31 18:13 UTC] diogotbrito at gmail dot com
This BUG also affects db2(pdo_ibm).

Works:
    $pdo = new PDO("ibm:HOSTNAME=xxx;DATABASE=SAMPLE;PORT=10099", "db2admin",   "lookupsc.1");

    $val = file_get_contents("fundo1.png");

    $stm = $pdo->prepare("UPDATE DB2ADMIN.PICTURES SET IMAGEM = :field_blob");
    $stm->bindParam(":field_blob", $val, PDO::PARAM_LOB);
    $stm->execute();

    $stm = $pdo->query("SELECT IMAGEM FROM DB2ADMIN.PICTURES");
    foreach($stm->fetch(PDO::FETCH_NUM ) as $row)
    {
        $a = stream_get_contents($row);
        var_dump($a);
    }

Outputs: the binary: string(877) "�PNG  IHDR� ....

Doesnt't Works:

    $pdo = new PDO("ibm:HOSTNAME=xxx;DATABASE=SAMPLE;PORT=10099", "db2admin",   "lookupsc.1");

    $val = file_get_contents("fundo1.png");

    $stm = $pdo->prepare("UPDATE DB2ADMIN.PICTURES SET IMAGEM = :field_blob");
    $stm->bindParam(":field_blob", $val, PDO::PARAM_LOB);
    $stm->execute();

    $stm = $pdo->query("SELECT IMAGEM FROM DB2ADMIN.PICTURES");
    foreach($stm->fetchAll(PDO::FETCH_NUM ) as $row)
    {
        $a = stream_get_contents($row[0]);

        var_dump($a);
    }

Outputs: string(0) ""
 [2021-11-19 22:32 UTC] michael dot vorisek at email dot cz
Please reopen, I can confirm this issue and the behaviour described in the last post - when multiple rows are selected using fetchAll, the CLOB column value is the same/"" (or null) for all rows.

When I restrict a select condition to select only one row, CLOB column has different/correct value than when the result when all rows are selected. Very dangerous bug, must be fixed asap.
 [2023-07-05 10:24 UTC] yao at codeafro dot com
This bug still exist in PHP 8.1.18
OS: Windows 11
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 17:01:29 2024 UTC