Increase timeout of dblib connection with PDO

Asked

Viewed 1,078 times

10

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

How to increase connection timeout dblib with PDO?

I tried to use array(\PDO::ATTR_TIMEOUT => 10) as an option on the connection PDO but 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 larger timeout? can be using any lib that works with linux.

I tried to use setAttribute(\PDO::ATTR_TIMEOUT, 10); and 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 connection did not change anything.

  • Ever tried to use PDO::setAttribute?

  • Also not working: Warning: PDO::setAttribute(): SQLSTATE[IM001]: Driver does not support this Function: driver does not support Setting Attributes

  • In that case it may be necessary to use another driver, using PDO::getAvailableDrivers returns the drivers available. Before choosing one, check if it supports the setAttribute. See the list of drivers here.

  • @stderr, knowing that PDO_SQLSRV only works on Windows servers, which other option I have for connection to MSSQL Server ?

  • According to the documentation, the option is PDO_ODBC, see also this page on msdn for more details.

  • Try to put ini_set("default_socket_timeout", 10); before connection.

  • @Augusto, thank you for your help, but you haven’t changed a bit.

Show 2 more comments

2 answers

2

Try this here

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

OR

You can also try adding in the string Connection

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

more information: http://php.net/manual/de/ref.pdo-sqlsrv.connection.php

-2

You can use

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

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

Example with mysql:

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

You will find more references including to other databases in the official php documentation.

Follow the link:

http://php.net/manual/en/pdo.connections.php

Browser other questions tagged

You are not signed in. Login or sign up in order to post.