Increase dblib connection timeout with PDO

10

In a connection to an external server ( MS SQL SERVER ), from another system with which I integrate some data, it is extremely slow, and thus the connection to the database gives error.

How to increase the timeout of the PDB connection with PDO ?

I tried to use array(\PDO::ATTR_TIMEOUT => 10) as an option on the PDO connection but it generates the following error:

  

Warning: PDO :: __ construct (): SQLSTATE [IM001]: Driver does not support this function: driver does not support setting attributes in /var/www/core/class/Banco/GkBanco.php on line 25

How to connect to MSSQL with a longer timeout? can be using any lib that works with linux .

I tried to use setAttribute(\PDO::ATTR_TIMEOUT, 10); and it generates the following error:

  

Warning: PDO :: setAttribute (): SQLSTATE [IM001]: Driver does not support this function: driver does not support setting attributes

I tried to add ini_set("default_socket_timeout", 30); before the connection did not change anything.

    
asked by anonymous 05.09.2016 / 16:55

2 answers

2

Try this here

$pdo->setAttribute(\PDO::SQLSRV_ATTR_QUERY_TIMEOUT, 5);

OR

You can also try adding in the connection string

$pdo = new \PDO("sqlsrv:Server=server;Database=dbname;LoginTimeout=5", 'username', 'password');

More information: link

    
13.10.2016 / 23:52
-2

You can use

$pdoConnection->setAttribute(\PDO::SQLSRV_ATTR_QUERY_TIMEOUT, 10);

However you can insert this directly into the connection query string with your database.

Example with mysql:

$dbh = new PDO('mysql:host=localhost;dbname=test;timeout', $user, $pass);

You'll find even more references to other databases in the official php documentation.

Follow the link:

link

    
22.02.2017 / 14:09