xref: /PHP-7.4/ext/pdo/tests/bug_38253.phpt (revision 26dfce7f)
1--TEST--
2PDO Common: Bug #38253 (PDO produces segfault with default fetch mode)
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
13if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.__DIR__ . '/../../pdo/tests/');
14require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
15$pdo = PDOTest::factory();
16
17$pdo->exec ("create table test (id integer primary key, n varchar(255))");
18$pdo->exec ("INSERT INTO test (id, n) VALUES (1, 'hi')");
19
20$pdo->setAttribute (PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_CLASS);
21$stmt = $pdo->prepare ("SELECT * FROM test");
22$stmt->execute();
23var_dump($stmt->fetchAll());
24
25$pdo->setAttribute (PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_FUNC);
26$stmt = $pdo->prepare ("SELECT * FROM test");
27$stmt->execute();
28var_dump($stmt->fetchAll());
29
30?>
31--EXPECTF--
32Warning: PDOStatement::fetchAll(): SQLSTATE[HY000]: General error: No fetch class specified in %s on line %d
33
34Warning: PDOStatement::fetchAll(): SQLSTATE[HY000]: General error%s on line %d
35array(0) {
36}
37
38Warning: PDOStatement::fetchAll(): SQLSTATE[HY000]: General error: No fetch function specified in %s on line %d
39
40Warning: PDOStatement::fetchAll(): SQLSTATE[HY000]: General error%s on line %d
41array(0) {
42}
43