xref: /php-src/ext/pdo_dblib/tests/timeout.phpt (revision d6a0b3af)
1--TEST--
2PDO_DBLIB: Set query timeouts
3--EXTENSIONS--
4pdo_dblib
5--SKIPIF--
6<?php
7if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
8require __DIR__ . '/config.inc';
9getDbConnection();
10?>
11--FILE--
12<?php
13require __DIR__ . '/config.inc';
14
15$db = getDbConnection();
16
17$sql = 'WAITFOR DELAY \'00:00:02\'';
18
19// regular timeout attribute, set after instance created, will affect query timeout, causing this query to fail
20$db = getDbConnection();
21$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
22$db->setAttribute(PDO::ATTR_TIMEOUT, 1);
23$stmt = $db->prepare($sql);
24if (!$stmt->execute()) {
25    echo "OK\n";
26
27    // expect some kind of error code
28    if ($stmt->errorCode() != '00000') {
29        echo "OK\n";
30    }
31}
32
33// pdo_dblib-specific timeout attribute, set after instance created, will control query timeout, causing this query to fail
34$db = getDbConnection();
35$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
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 = getDbConnection(PDO::class, [PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT, 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 = getDbConnection(PDO::class, [PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT, 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
81