xref: /PHP-5.4/ext/pdo/tests/bug_39656.phpt (revision be0793d2)
1--TEST--
2PDO Common: Bug #39656 (Crash when calling fetch() on a PDO statment object after closeCursor())
3--SKIPIF--
4<?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
13
14if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.dirname(__FILE__) . '/../../pdo/tests/');
15require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
16$db = PDOTest::factory();
17
18@$db->exec("DROP TABLE test");
19$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
20
21$db->exec("CREATE TABLE test (id INTEGER NOT NULL PRIMARY KEY, usr VARCHAR( 256 ) NOT NULL)");
22$db->exec("INSERT INTO test (id, usr) VALUES (1, 'user')");
23
24$stmt = $db->prepare("SELECT * FROM test 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
35@$db->exec("DROP TABLE test");
36echo "Done\n";
37?>
38--EXPECT--
39array(4) {
40  ["id"]=>
41  string(1) "1"
42  [0]=>
43  string(1) "1"
44  ["usr"]=>
45  string(4) "user"
46  [1]=>
47  string(4) "user"
48}
49bool(false)
50Done
51
52