Skip to content

PDO_DBLIB: Fetching from statements sharing a conection results in wrong values being returned #11552

Open
@harrison3000

Description

@harrison3000

Description

When using pdo_dblib, making 2 queries at the same time using the same conection results in corrupt statements
The keys are correct, but the results are from the last query
It's as if both statements are somehow sharing the same cursor under the hood

The following code:

<?php
$user = "REDACTED";
$pass = "REDACTED";
$host = "REDACTED";
$db   = "REDACTED";

$con = new \PDO("dblib:host=$host;dbname=$db;version=7.3;charset=UTF-8",$user,$pass,array(
    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
));

$sta = $con->query("SELECT *
FROM (
    VALUES ('A0'),
           ('A1'),
           ('A2')
) AS MyTable(A)");

$stb = $con->query("SELECT *
FROM (
    VALUES ('B0'),
           ('B1'),
           ('B2')
) AS MyTable(B)");

var_export($sta->fetch()); echo "\n";
var_export($stb->fetch()); echo "\n";

var_export($sta->fetch()); echo "\n";
var_export($stb->fetch()); echo "\n";

Resulted in this output:

array (
  'A' => 'B0',
)
array (
  'B' => 'B1',
)
array (
  'A' => 'B2',
)
false

But I expected this output instead:

array (
  'A' => 'A0',
)
array (
  'B' => 'B0',
)
array (
  'A' => 'A1',
)
array (
  'B' => 'B1',
)

PHP Version

PHP 8.2.7

Operating System

Ubuntu 23.04

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions