Skip to content

An error occurs in set_attribute when using PDO SQLSRV #12038

Closed as not planned
Closed as not planned
@SakiTakamachi

Description

@SakiTakamachi

Description

The following code:

<?php

// my env
$pdo = new PDO('sqlsrv:server=mssql-server;database=test;', 'test_user', 'p@ssw0rd');
$pdo->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);

Resulted in this output:

Fatal error: Uncaught PDOException: SQLSTATE[IMSSP]: An invalid attribute was designated on the PDO object. in /var/www/html/test.php:5
Stack trace:
#0 /var/www/html/test.php(5): PDO->setAttribute(17, false)
#1 {main}
  thrown in /var/www/html/test.php on line 5

A change here is triggering the error.
#11622

The essence of the problem is that PDO SQLSRV is throwing an error instead of returning false when set_attribute fails.
microsoft/msphpsql#1468
laravel/framework#47937

I've been working on this issue for about 20 days now and the hotfix for PDO SQLSRV has not yet been released and things are looking a little shady.

However, since there are many people who are in trouble, I thought about creating a PR for a workaround with php-src. What do you think?
#12039

remarks:
I've checked all the PDO drivers provided by PECL and found that only one, PDO SQLSRV, gives an error under the same conditions.

PHP Version

PHP 8.1.22+, 8.2.9+, 8.3.0+

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