xref: /PHP-7.3/ext/pdo/tests/bug_64172.phpt (revision b746e698)
1--TEST--
2PDO Common: Bug #64172 errorInfo is not properly cleaned up
3--SKIPIF--
4<?php # vim:ft=php
5if (!extension_loaded('pdo')) die('skip');
6$dir = getenv('REDIR_TEST_DIR');
7if (false == $dir) die('skip no driver');
8require_once $dir . 'pdo_test.inc';
9PDOTest::skip();
10?>
11--FILE--
12<?php
13if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.dirname(__FILE__) . '/../../pdo/tests/');
14require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
15
16$db = PDOTest::factory();
17
18@$db->exec("DROP TABLE test");
19$db->exec("CREATE TABLE test (x int)");
20$db->exec("INSERT INTO test VALUES (1)");
21
22echo "===FAIL===\n";
23$db->query('SELECT * FROM bad_table');
24echo "\n";
25echo "===TEST===\n";
26var_dump(is_string($db->errorInfo()[0])) . "\n";
27var_dump(is_int($db->errorInfo()[1])) . "\n";
28var_dump(is_string($db->errorInfo()[2])) . "\n";
29echo "===GOOD===\n";
30$stmt = $db->query('SELECT * FROM test');
31$stmt->fetchAll();
32$stmt = null;
33var_dump($db->errorInfo());
34
35echo "===FAIL===\n";
36$db->exec("INSERT INTO bad_table VALUES(1)");
37echo "\n";
38echo "===TEST===\n";
39var_dump(is_string($db->errorInfo()[0])) . "\n";
40var_dump(is_int($db->errorInfo()[1])) . "\n";
41var_dump(is_string($db->errorInfo()[2])) . "\n";
42echo "===GOOD===\n";
43$db->exec("INSERT INTO test VALUES (2)");
44var_dump($db->errorInfo());
45
46$db->exec("DROP TABLE test");
47?>
48===DONE===
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===DONE===
85