xref: /PHP-8.1/ext/pdo/tests/pdo_015.phpt (revision 74859783)
1--TEST--
2PDO Common: PDO::FETCH_COLUMN
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), val2 VARCHAR(20))');
19$db->exec('INSERT INTO test VALUES(1, \'A\', \'A2\')');
20$db->exec('INSERT INTO test VALUES(2, \'A\', \'B2\')');
21
22$select1 = $db->prepare('SELECT id, val, val2 FROM test');
23$select2 = $db->prepare('SELECT val, val2 FROM test');
24
25$select1->execute();
26var_dump($select1->fetchAll(PDO::FETCH_COLUMN));
27$select1->execute();
28var_dump($select1->fetchAll(PDO::FETCH_COLUMN, 2));
29$select1->execute();
30var_dump($select1->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_GROUP));
31$select1->execute();
32var_dump($select1->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_UNIQUE));
33$select1->execute();
34var_dump($select1->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_UNIQUE, 0));
35$select1->execute();
36var_dump($select1->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_UNIQUE, 1));
37$select1->execute();
38var_dump($select1->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_UNIQUE, 2));
39
40$select2->execute();
41var_dump($select2->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_GROUP));
42
43?>
44--EXPECT--
45array(2) {
46  [0]=>
47  string(1) "1"
48  [1]=>
49  string(1) "2"
50}
51array(2) {
52  [0]=>
53  string(2) "A2"
54  [1]=>
55  string(2) "B2"
56}
57array(2) {
58  [1]=>
59  array(1) {
60    [0]=>
61    string(1) "A"
62  }
63  [2]=>
64  array(1) {
65    [0]=>
66    string(1) "A"
67  }
68}
69array(2) {
70  [1]=>
71  string(1) "A"
72  [2]=>
73  string(1) "A"
74}
75array(2) {
76  [1]=>
77  string(1) "1"
78  [2]=>
79  string(1) "2"
80}
81array(2) {
82  [1]=>
83  string(1) "A"
84  [2]=>
85  string(1) "A"
86}
87array(2) {
88  [1]=>
89  string(2) "A2"
90  [2]=>
91  string(2) "B2"
92}
93array(1) {
94  ["A"]=>
95  array(2) {
96    [0]=>
97    string(2) "A2"
98    [1]=>
99    string(2) "B2"
100  }
101}
102