PHP PDO connection timeout for database use and determine


Normally you can read from the database connection timeout in PHP using:

$pdo = new PDO('mysql:host=localhost;port=80;dbname=xxx', 'xxx', 'xxxx');
$pdo->getAttribute(PDO::ATTR_TIMEOUT);

However, this gives the error message with my old version of PDO:

SQLSTATE[IM001]: Driver does not support this function: driver does not support that attribute

So I've written a testscript, with the you can provoke the timeout (the measurement of time is not included, would be nice, If someone could post that):

$pdo = new PDO('mysql:host=localhost;port=80;dbname=xxx', 'xxx', 'xxxx');

Thus, the timeout is raised.

To extend the timeout, can you get the parameter of PDO::Use ATTR_TIMEOUT:

$pdo = new PDO('mysql:host=localhost;port=80;dbname=xxx', 'xxx', 'xxxx', array(
   PDO::ATTR_TIMEOUT => 5
));