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