Bug #46728 [Com]: PDO(OCI)::fetchAll with stream (CLOB) : resource contains always same value

From: Date: Thu, 12 Jan 2017 07:40:17 +0000
Subject: Bug #46728 [Com]: PDO(OCI)::fetchAll with stream (CLOB) : resource contains always same value
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-206548@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=46728&edit=1

 ID:                 46728
 Comment by:         anatoly dot rugalev at gmail dot com
 Reported by:        berlioz at nicematin dot fr
 Summary:            PDO(OCI)::fetchAll with stream (CLOB) : resource
                     contains always same value
 Status:             No Feedback
 Type:               Bug
 Package:            PDO OCI
 Operating System:   Linux (All ?)
 PHP Version:        5.2.6
 Block user comment: N
 Private report:     N

 New Comment:

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;
}


Previous Comments:
------------------------------------------------------------------------
[2009-05-03 01:00:19] 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".

------------------------------------------------------------------------
[2009-04-25 15:23:18] 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-02-22 04:50:15] 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-02-22 04:48:09] 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.

------------------------------------------------------------------------
[2008-12-02 08:56:07] 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


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=46728&edit=1


Thread (8 messages)

« previous php.bugs (#206548) next »