php / php-src

The PHP Interpreter
https://www.php.net
Other
38.23k stars 7.75k forks source link

pdo_oci poiting all records to the last resource blob when using fetchAll #15967

Open diogotoscano opened 1 month ago

diogotoscano commented 1 month ago

Description

The following code:

<?php

$pdo = new PDO("oci:dbname=xxx.xxx.xxx.xxx/xxxxx", "xxxx",   "xxxxx);
$pdo->setAttribute(PDO::ATTR_AUTOCOMMIT, false);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

//doesnt work 
$stm = $pdo->query("SELECT PICTURE FROM USU_19013.CATEGORIES");
foreach($stm->fetchAll(PDO::FETCH_NUM ) as $row)
{
    if(is_resource($row[0]))
    {
        $blob = stream_get_contents($row[0]);
        echo strlen($blob);
    }
    echo "<br>";
}

echo "-----------------------------------<br>";

//works
$stmt = $pdo->query("SELECT PICTURE FROM USU_19013.CATEGORIES");
while ($row = $stmt->fetch(PDO::FETCH_NUM)) {

    $blob = stream_get_contents($row[0]);
    echo strlen($blob);
    echo "<br>";
}

Resulted in this output:

6592
6592
6592
6592
6592
6592
6592
6592
-----------------------------------
805361
12984
29416
6768
9104
16652
8864
6592

But I expected this output instead:

805361
12984
29416
6768
9104
16652
8864
6592
-----------------------------------
805361
12984
29416
6768
9104
16652
8864
6592

PHP Version

8.1.28

Operating System

Windows NT DESKTOP-VKLN5U7 10.0 build 22631 (Windows 11) AMD64

cmb69 commented 1 month ago

Does this also happen with any of the actively supported PHP versions, (i.e. PHP 8.2 or PHP 8.3)?

diogotoscano commented 1 month ago

Does this also happen with any of the actively supported PHP versions, (i.e. PHP 8.2 or PHP 8.3)?

Same output with: PHP Version 8.2.12 PHP Version 8.3.11 - Aug 27 2024 21:26:18