PDO::getAttribute関数では、PDO::ATTR_TIMEOUTを呼び出すことができない。呼び出そうとすると以下のようなエラーが出る。
<?php
define('HOST', 'localhost');
define('DB_NAME', 'nissin');
define('DB_USER', 'nissin');
define('DB_PASS', 'nissin');
$dsn = 'mysql:host='. HOST. ';dbname='. DB_NAME;
try {
$conn = new PDO($dsn, DB_USER, DB_PASS, array(PDO::ATTR_TIMEOUT => 5));
} catch( PDOException $e ) {
die( $e->getMessage() );
}
$conn->setAttribute(PDO::ATTR_TIMEOUT, 10);
echo $conn->getAttribute(2);
?>
Warning: PDO::getAttribute(): SQLSTATE[IM001]: Driver does not support this function: driver does not support that attribute in C:\home\sandbox\php\pdo_timeout.php on line 14
PDO::ATTR_TIMEOUTは、呼び出し限定のためPDO::setAttribute関数で、DB接続時間を設定するためにのみ使用可能であーる。