extension version 4.3.0 (per php -i)
SQL2016
CentOS Linux release 7.4.1708 (Core)
PHP 7.1.15
13.1.9.2 (per yum info msodbcsql)
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 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
/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)
----------------------------------
Yes @mathieuk we can reproduce this and will get back to you after some investigation. Thanks for your patience.
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.
This indeed seems fixed with a more up to date unixODBC. Thanks for looking into this!
Great! I'm going to close this issue, @mathieuk
Please feel free to reopen in case you have more questions.
Dear @yitam , does it unixODBC driver be applied to the server?
Thanks in advance!
@marcellopato I'm not sure I understand what you're asking about unixODBC. ODBC driver depends on the driver manager unixODBC and by installing ODBC 17 will update unixODBC as well.
@yitam Hi and thanks for the answer. I meant if the unixODBC should be installed on the dev and production server.
I do dev on a mac. The MSSQL is running on an aws server witch I don麓t know yet if is Linux or Windows.
I hope I made myself more clear this time and thanks again for your help!
Most helpful comment
Yes @mathieuk we can reproduce this and will get back to you after some investigation. Thanks for your patience.