1--TEST-- 2PDO_DBLIB: Set query timeouts 3--SKIPIF-- 4<?php 5if (!extension_loaded('pdo_dblib')) die('skip not loaded'); 6if (getenv("SKIP_SLOW_TESTS")) die("skip slow test"); 7require dirname(__FILE__) . '/config.inc'; 8?> 9--FILE-- 10<?php 11require dirname(__FILE__) . '/config.inc'; 12 13$sql = 'WAITFOR DELAY \'00:00:02\''; 14 15// querying without a timeout will succeed 16$stmt = $db->prepare($sql); 17if ($stmt->execute()) { 18 echo "OK\n"; 19} 20 21// regular timeout attribute, set after instance created, will affect query timeout, causing this query to fail 22$db = new PDO($dsn, $user, $pass); 23$db->setAttribute(PDO::ATTR_TIMEOUT, 1); 24$stmt = $db->prepare($sql); 25if (!$stmt->execute()) { 26 echo "OK\n"; 27 28 // expect some kind of error code 29 if ($stmt->errorCode() != '00000') { 30 echo "OK\n"; 31 } 32} 33 34// pdo_dblib-specific timeout attribute, set after instance created, will control query timeout, causing this query to fail 35$db = new PDO($dsn, $user, $pass); 36$db->setAttribute(PDO::DBLIB_ATTR_QUERY_TIMEOUT, 1); 37$stmt = $db->prepare($sql); 38if (!$stmt->execute()) { 39 echo "OK\n"; 40 41 // expect some kind of error code 42 if ($stmt->errorCode() != '00000') { 43 echo "OK\n"; 44 } 45} 46 47// regular timeout attribute will affect query timeout, causing this query to fail 48$db = new PDO($dsn, $user, $pass, [PDO::ATTR_TIMEOUT => 1]); 49$stmt = $db->prepare($sql); 50if (!$stmt->execute()) { 51 echo "OK\n"; 52 53 // expect some kind of error code 54 if ($stmt->errorCode() != '00000') { 55 echo "OK\n"; 56 } 57} 58 59// pdo_dblib-specific timeout attribute will control query timeout, causing this query to fail 60$db = new PDO($dsn, $user, $pass, [PDO::DBLIB_ATTR_QUERY_TIMEOUT => 1]); 61$stmt = $db->prepare($sql); 62if (!$stmt->execute()) { 63 echo "OK\n"; 64 65 // expect some kind of error code 66 if ($stmt->errorCode() != '00000') { 67 echo "OK\n"; 68 } 69} 70 71?> 72--EXPECT-- 73OK 74OK 75OK 76OK 77OK 78OK 79OK 80OK 81OK 82