New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDO::getAttribute(PDO::ATTR_SERVER_VERSION) fails on connection from connection pool #733

Closed
mathieuk opened this Issue Apr 3, 2018 · 4 comments

Comments

Projects
None yet
2 participants
@mathieuk

mathieuk commented Apr 3, 2018

Driver version or file name

extension version 4.3.0 (per php -i)

SQL Server version

SQL2016

Client operating system

CentOS Linux release 7.4.1708 (Core)

PHP version

PHP 7.1.15

Microsoft ODBC Driver version

13.1.9.2 (per yum info msodbcsql)

Problem description

When using connection pooling requesting the Server Version attribute (PDO::ATTR_SERVER_VERSION) the request fails on the second request in the same process.

The reason that I ran into this quite specific problem is that the framework used (Laravel) uses Doctrine/DBAL which checks this attribute (see https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Driver/PDOConnection.php#L71). The code below is thus simplified.

Expected behavior and actual behavior

Expected behaviour was to receive a value for the attribute.

Actual behaviour is the code works fine for a non-connection-pool-connection (Pooling=no in odbcinst.ini) but a warning is thrown by PDO::getAttribute() when the connection would be from the connection pool:

PHP Warning: PDO::getAttribute(): SQLSTATE[IM001]: Driver does not support this function: driver does not support that attribute in /path/to/test.php on line 6

Repro code

/etc/odbcinst.ini:

[ODBC]
Pooling=Yes

[ODBC Driver 13 for SQL Server]
Description=Microsoft ODBC Driver 13 for SQL Server
Driver=/opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.1.so.9.2
UsageCount=1
CPTimeout=120

test.php:

<?php

for ($i = 0; $i < 4; $i++) { 
    $pdo = new PDO('sqlsrv:Server=HOSTNAMEGOESHERE;Database=EXISTINGDATABASEGOESHERE', 'user', 'password');
    var_dump($pdo->getAttribute(PDO::ATTR_SERVER_VERSION));
    echo "----------------------------------\n";
}

?>

Expected result:

string(10) "13.00.4001"
----------------------------------
string(10) "13.00.4001"
----------------------------------
string(10) "13.00.4001"
----------------------------------
string(10) "13.00.4001"
----------------------------------

Actual result:

string(10) "13.00.4001"
----------------------------------
string(10) "13.00.4001"
----------------------------------
PHP Warning:  PDO::getAttribute(): SQLSTATE[IM001]: Driver does not support this function: driver does not support that attribute in test.php on line 6
bool(false)
----------------------------------
PHP Warning:  PDO::getAttribute(): SQLSTATE[IM001]: Driver does not support this function: driver does not support that attribute in test.php on line 6
bool(false)
----------------------------------
@yitam

This comment has been minimized.

Member

yitam commented Apr 3, 2018

Yes @mathieuk we can reproduce this and will get back to you after some investigation. Thanks for your patience.

@yitam

This comment has been minimized.

Member

yitam commented Apr 10, 2018

Hi @mathieuk
The problem lies in unixodbc. I can reproduce the same problem in both Ubuntu 16.04 and CentOS 7 with ODBC 17.1.

However, I did test that with unixODBC 2.3.6 , and the problem goes away.

@yitam yitam added the unixODBC label Apr 10, 2018

@mathieuk

This comment has been minimized.

mathieuk commented Apr 18, 2018

This indeed seems fixed with a more up to date unixODBC. Thanks for looking into this!

@yitam

This comment has been minimized.

Member

yitam commented Apr 18, 2018

Great! I'm going to close this issue, @mathieuk
Please feel free to reopen in case you have more questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment