Skip to content

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

Closed
@SakiTakamachi

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

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