php / php/php-src

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

未关闭
#11,552 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Bug Extension: pdo_dblib Status: Verified
主要语言
C
星标
40.4k
派生
8.2k
平均合并
2 天 15 小时
30 天内合并 PR
103

描述

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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从提供的 PHP 重现代码所涉及的 pdo_dblib 语句处理开始,重点关注两个语句共享一个连接时 fetch() 的行为。重现交错查询,并验证每个语句都按预期顺序返回属于自己的 A 或 B 行。

由索引模型根据 Issue 内容生成。

评估

技术栈
c, php
领域
backend, databases
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。