xref: /PHP-8.1/ext/pdo/tests/bug_64172.phpt (revision 74859783)
1--TEST--
2PDO Common: Bug #64172 errorInfo is not properly cleaned up
3--EXTENSIONS--
4pdo
5--SKIPIF--
6<?php
7$dir = getenv('REDIR_TEST_DIR');
8if (false == $dir) die('skip no driver');
9require_once $dir . 'pdo_test.inc';
10PDOTest::skip();
11?>
12--FILE--
13<?php
14if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.__DIR__ . '/../../pdo/tests/');
15require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
16
17$db = PDOTest::factory();
18
19@$db->exec("DROP TABLE test");
20$db->exec("CREATE TABLE test (x int)");
21$db->exec("INSERT INTO test VALUES (1)");
22
23echo "===FAIL===\n";
24$db->query('SELECT * FROM bad_table');
25echo "\n";
26echo "===TEST===\n";
27var_dump(is_string($db->errorInfo()[0])) . "\n";
28var_dump(is_int($db->errorInfo()[1])) . "\n";
29var_dump(is_string($db->errorInfo()[2])) . "\n";
30echo "===GOOD===\n";
31$stmt = $db->query('SELECT * FROM test');
32$stmt->fetchAll();
33$stmt = null;
34var_dump($db->errorInfo());
35
36echo "===FAIL===\n";
37$db->exec("INSERT INTO bad_table VALUES(1)");
38echo "\n";
39echo "===TEST===\n";
40var_dump(is_string($db->errorInfo()[0])) . "\n";
41var_dump(is_int($db->errorInfo()[1])) . "\n";
42var_dump(is_string($db->errorInfo()[2])) . "\n";
43echo "===GOOD===\n";
44$db->exec("INSERT INTO test VALUES (2)");
45var_dump($db->errorInfo());
46
47$db->exec("DROP TABLE test");
48?>
49--EXPECTF--
50===FAIL===
51
52Warning: PDO::query(): SQLSTATE[%s]: %s
53%A
54===TEST===
55bool(true)
56bool(true)
57bool(true)
58===GOOD===
59array(3) {
60  [0]=>
61  string(5) "00000"
62  [1]=>
63  NULL
64  [2]=>
65  NULL
66}
67===FAIL===
68
69Warning: PDO::exec(): SQLSTATE[%s]: %s
70%A
71===TEST===
72bool(true)
73bool(true)
74bool(true)
75===GOOD===
76array(3) {
77  [0]=>
78  string(5) "00000"
79  [1]=>
80  NULL
81  [2]=>
82  NULL
83}
84