xref: /PHP-8.3/ext/pdo_dblib/tests/timeout.phpt (revision 74859783)
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';
9?>
10--FILE--
11<?php
12require __DIR__ . '/config.inc';
13
14$sql = 'WAITFOR DELAY \'00:00:02\'';
15
16// regular timeout attribute, set after instance created, will affect query timeout, causing this query to fail
17$db = new PDO($dsn, $user, $pass);
18$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
19$db->setAttribute(PDO::ATTR_TIMEOUT, 1);
20$stmt = $db->prepare($sql);
21if (!$stmt->execute()) {
22    echo "OK\n";
23
24    // expect some kind of error code
25    if ($stmt->errorCode() != '00000') {
26        echo "OK\n";
27    }
28}
29
30// pdo_dblib-specific timeout attribute, set after instance created, will control query timeout, causing this query to fail
31$db = new PDO($dsn, $user, $pass);
32$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
33$db->setAttribute(PDO::DBLIB_ATTR_QUERY_TIMEOUT, 1);
34$stmt = $db->prepare($sql);
35if (!$stmt->execute()) {
36    echo "OK\n";
37
38    // expect some kind of error code
39    if ($stmt->errorCode() != '00000') {
40        echo "OK\n";
41    }
42}
43
44// regular timeout attribute will affect query timeout, causing this query to fail
45$db = new PDO($dsn, $user, $pass, [PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT, PDO::ATTR_TIMEOUT => 1]);
46$stmt = $db->prepare($sql);
47if (!$stmt->execute()) {
48    echo "OK\n";
49
50    // expect some kind of error code
51    if ($stmt->errorCode() != '00000') {
52        echo "OK\n";
53    }
54}
55
56// pdo_dblib-specific timeout attribute will control query timeout, causing this query to fail
57$db = new PDO($dsn, $user, $pass, [PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT, PDO::DBLIB_ATTR_QUERY_TIMEOUT => 1]);
58$stmt = $db->prepare($sql);
59if (!$stmt->execute()) {
60    echo "OK\n";
61
62    // expect some kind of error code
63    if ($stmt->errorCode() != '00000') {
64        echo "OK\n";
65    }
66}
67
68?>
69--EXPECT--
70OK
71OK
72OK
73OK
74OK
75OK
76OK
77OK
78