lingo
lingo

Reputation: 1908

PDO sqlsrv database connection timeout

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.

Upvotes: 5

Views: 5973

Answers (1)

kba
kba

Reputation: 4310

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.

Upvotes: 10

Related Questions