xref: /PHP-8.3/ext/pdo/tests/pdo_006.phpt (revision 74859783)
1--TEST--
2PDO Common: PDO::FETCH_GROUP
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_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
16$db = PDOTest::factory();
17
18$db->exec('CREATE TABLE test(id int NOT NULL PRIMARY KEY, val VARCHAR(10))');
19$db->exec("INSERT INTO test VALUES(1, 'A')");
20$db->exec("INSERT INTO test VALUES(2, 'A')");
21$db->exec("INSERT INTO test VALUES(3, 'C')");
22
23$stmt = $db->prepare('SELECT val, id from test');
24
25$stmt->execute();
26var_dump($stmt->fetchAll(PDO::FETCH_NUM|PDO::FETCH_GROUP));
27
28$stmt->execute();
29var_dump($stmt->fetchAll(PDO::FETCH_ASSOC|PDO::FETCH_GROUP));
30
31?>
32--EXPECT--
33array(2) {
34  ["A"]=>
35  array(2) {
36    [0]=>
37    array(1) {
38      [0]=>
39      string(1) "1"
40    }
41    [1]=>
42    array(1) {
43      [0]=>
44      string(1) "2"
45    }
46  }
47  ["C"]=>
48  array(1) {
49    [0]=>
50    array(1) {
51      [0]=>
52      string(1) "3"
53    }
54  }
55}
56array(2) {
57  ["A"]=>
58  array(2) {
59    [0]=>
60    array(1) {
61      ["id"]=>
62      string(1) "1"
63    }
64    [1]=>
65    array(1) {
66      ["id"]=>
67      string(1) "2"
68    }
69  }
70  ["C"]=>
71  array(1) {
72    [0]=>
73    array(1) {
74      ["id"]=>
75      string(1) "3"
76    }
77  }
78}
79