4

With MySQL I can use

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

to set connection timeout value. But when I'm using sqlsrv driver, it's working different. Can you explain how to set connection timeout with sqlsrv?

Thanks in advance.

lingo
  • 1,848
  • 6
  • 28
  • 56

1 Answers1

7

Try this (http://php.net/manual/de/ref.pdo-sqlsrv.connection.php):

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

or this (https://technet.microsoft.com/en-us/library/ff628164(v=sql.105).aspx):

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

But second solutions should work for normal query only. Hopefully, one of these solutions will help you.

kba
  • 4,190
  • 2
  • 15
  • 24