Skip to content

[pdo_odbc] Unable to turn on autocommit mode with setAttribute #12767

Closed

Description

@SakiTakamachi

Description

The following code:

<?php
$dsn = "/* your dsn */";
$user = "/* your user */";
$pass = "/* your pass */";

$db = new PDO($dsn, $user, $pass);
$db->exec("CREATE TABLE test (id INT, name VARCHAR(255))");
unset($db);

$db = new PDO($dsn, $user, $pass, [
    PDO::ATTR_AUTOCOMMIT => 0,
]);

$db->setAttribute(PDO::ATTR_AUTOCOMMIT, 1);
$db->query("INSERT INTO test (id, name) VALUES (1, 'test')");
unset($db);

$db = new PDO($dsn, $user, $pass);

$r = $db->query("SELECT * FROM test");
var_dump($r->fetchAll(PDO::FETCH_ASSOC));

Resulted in this output:

array(0) {
}

But I expected this output instead:

array(1) {
  [0]=>
  array(2) {
    ["id"]=>
    string(1) "1"
    ["name"]=>
    string(4) "test"
  }
}

I noticed the bug while reading the C source code, so I already know the cause. This is because when you change the attribute value after the constructor, nothing is done. The fix may be ready by the end of 8.1's bug fixes.

PHP Version

PHP8.1 ~ master

Operating System

No response

Activity

  1. SakiTakamachi commented on Nov 24, 2023

    @SakiTakamachi
    MemberAuthor

    There is a possibility that the behavior related to transactions may change slightly, so I would like to fix this for master.

  2. SakiTakamachi commented on Nov 24, 2023

    @SakiTakamachi
    MemberAuthor

    The main change is in the behavior when changing the autocommit mode while a transaction exists. I think this should probably be an error, but it could be a breaking change.

  3. added 2 commits that reference this issue on Dec 18, 2023
    933dccb
    dcef703
  4. added a commit that references this issue on Dec 18, 2023
    284b66b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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