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