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

Sean256
  • 2,849
  • 4
  • 30
  • 39
  • Are you connecting to MS SQL server? – Kuya Sep 10 '15 at 08:01
  • Yes we are. dblib is a mssql driver that uses freetds. – Sean256 Sep 11 '15 at 22:32
  • [This extension is not available anymore on Windows with PHP 5.3 or later.](http://php.net/manual/en/ref.pdo-dblib.php) says the dblib driver is not available on windows running PHP 5.3 or later. You should use `PDO_SQLSRV` instead. [PDO_SQLSRV](http://php.net/manual/en/ref.pdo-sqlsrv.connection.php) for more information. – Kuya Sep 12 '15 at 03:18
  • 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. – Sean256 Sep 12 '15 at 03:57
  • Try changing `$password,[PDO::ATTR_PERSISTENT=>true]);` to `$password, array(PDO::ATTR_PERSISTENT=>true));` – Kuya Sep 12 '15 at 04:03
  • 1
    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:` – Kuya Sep 12 '15 at 04:11

1 Answers1

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)