PDO_DBLIB: Fetching from statements sharing a conection results in wrong values being returned
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 40.4k
- Forks
- 8.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 96
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the pdo_dblib statement handling exercised by the provided PHP reproduction, focusing on how fetch() behaves for two statements sharing one connection. Reproduce the interleaved queries and verify that each statement returns its own A or B rows in the expected order.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, php
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100