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:23
Avg. Score:4.6 ± 0.7
Reproduced:22 of 23 (95.7%)
Same Version:3 (13.6%)
Same OS:13 (59.1%)
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
Have you experienced this issue?
Rate the importance of this bug to you:

 [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

Add a Patch

Pull Requests

Add a Pull Request

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: Fri Apr 19 03:01:27 2024 UTC