xref: /PHP-8.3/ext/pdo/tests/bug_44173.phpt (revision 74859783)
1--TEST--
2PDO Common: Bug #44173 (PDO->query() parameter parsing/checking needs an update)
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 getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
16$db = PDOTest::factory();
17
18$db->exec("CREATE TABLE test (x int)");
19$db->exec("INSERT INTO test VALUES (1)");
20
21
22// Bug entry [2] -- 1 is PDO::FETCH_LAZY
23try {
24    $stmt = $db->query("SELECT * FROM test", PDO::FETCH_LAZY, 0, []);
25    var_dump($stmt);
26} catch (\TypeError $e) {
27    echo $e->getMessage(), \PHP_EOL;
28}
29
30
31// Bug entry [3]
32try {
33    $stmt = $db->query("SELECT * FROM test", 'abc');
34} catch (TypeError $e) {
35    echo $e->getMessage(), "\n";
36}
37
38// Bug entry [4]
39try {
40    $stmt = $db->query("SELECT * FROM test", PDO::FETCH_CLASS, 0, 0, 0);
41    var_dump($stmt);
42} catch (\ArgumentCountError $e) {
43    echo $e->getMessage(), \PHP_EOL;
44}
45
46
47// Bug entry [5]
48try {
49    $stmt = $db->query("SELECT * FROM test", PDO::FETCH_INTO);
50    var_dump($stmt);
51} catch (\ArgumentCountError $e) {
52    echo $e->getMessage(), \PHP_EOL;
53}
54
55
56// Bug entry [6]
57try {
58    $stmt = $db->query("SELECT * FROM test", PDO::FETCH_COLUMN);
59    var_dump($stmt);
60} catch (\ArgumentCountError $e) {
61    echo $e->getMessage(), \PHP_EOL;
62}
63
64
65// Bug entry [7]
66try {
67    $stmt = $db->query("SELECT * FROM test", PDO::FETCH_CLASS);
68    var_dump($stmt);
69} catch (\ArgumentCountError $e) {
70    echo $e->getMessage(), \PHP_EOL;
71}
72
73
74?>
75--EXPECT--
76PDO::query() expects exactly 2 arguments for the fetch mode provided, 4 given
77PDO::query(): Argument #2 ($fetchMode) must be of type ?int, string given
78PDO::query() expects at most 4 arguments for the fetch mode provided, 5 given
79PDO::query() expects exactly 3 arguments for the fetch mode provided, 2 given
80PDO::query() expects exactly 3 arguments for the fetch mode provided, 2 given
81PDO::query() expects at least 3 arguments for the fetch mode provided, 2 given
82