xref: /php-src/ext/pdo/tests/bug_39656.phpt (revision f4a5db3e)
1--TEST--
2PDO Common: Bug #39656 (Crash when calling fetch() on a PDO statement object after closeCursor())
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
14
15if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.__DIR__ . '/../../pdo/tests/');
16require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
17$db = PDOTest::factory();
18
19$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
20
21$db->exec("CREATE TABLE test39656 (id INTEGER NOT NULL PRIMARY KEY, usr VARCHAR( 256 ) NOT NULL)");
22$db->exec("INSERT INTO test39656 (id, usr) VALUES (1, 'user')");
23
24$stmt = $db->prepare("SELECT * FROM test39656 WHERE id = ?");
25$stmt->bindValue(1, 1, PDO::PARAM_INT );
26$stmt->execute();
27$row = $stmt->fetch();
28var_dump( $row );
29
30$stmt->execute();
31$stmt->closeCursor();
32$row = $stmt->fetch(); // this line will crash CLI
33var_dump( $row );
34
35echo "Done\n";
36?>
37--CLEAN--
38<?php
39require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
40$db = PDOTest::factory();
41PDOTest::dropTableIfExists($db, "test39656");
42?>
43--EXPECT--
44array(4) {
45  ["id"]=>
46  string(1) "1"
47  [0]=>
48  string(1) "1"
49  ["usr"]=>
50  string(4) "user"
51  [1]=>
52  string(4) "user"
53}
54bool(false)
55Done
56