PHP PDO dblib (mssql) with persistent connections not working
Asked Answered
C

1

6

Following online examples and the documentation for PDO I have this one line for creating a PDO object using persistent connections:

$p = new PDO('dblib:host=SOMEHOSTNAME;dbname=SOMEDB',$user,$password,[PDO::ATTR_PERSISTENT=>true]);

Example on official documentation here: http://php.net/manual/en/pdo.connections.php

The error we get:

SQLSTATE[IM001]: Driver does not support this function: driver does not support setting attributes

Casias answered 8/9, 2015 at 20:35 Comment(6)
Are you connecting to MS SQL server?Forsyth
Yes we are. dblib is a mssql driver that uses freetds.Casias
This extension is not available anymore on Windows with PHP 5.3 or later. says the dblib driver is not available on windows running PHP 5.3 or later. You should use PDO_SQLSRV instead. PDO_SQLSRV for more information.Forsyth
You are 100% correct. I am using it on a nix system though and not Windows. I do have a Windows instance using SQLSRV for something else and it's fine. I didn't think I needed to mention I was on Nix since dblib is only on it.Casias
Try changing $password,[PDO::ATTR_PERSISTENT=>true]); to $password, array(PDO::ATTR_PERSISTENT=>true));Forsyth
From my reasearch the pdo driver dblib does not allow the setting of attributes. That's why you get the error message. Try changing dblib: to sqlsrv:Forsyth
C
0

You can try this by installing PDO ODBC Driver.
If you're using the PDO ODBC driver and your ODBC libraries support ODBC Connection Pooling (unixODBC and Windows are two that do; there may be more), then it's recommended that you don't use persistent PDO connections, and instead leave the connection caching to the ODBC Connection Pooling layer... http://php.net/manual/en/pdo.connections.php (Example #4 Persistent connections: Note 2)

Chain answered 2/12, 2018 at 18:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.