xref: /PHP-8.3/ext/pdo/tests/pdo_007.phpt (revision 74859783)
1--TEST--
2PDO Common: PDO::FETCH_UNIQUE
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 CHAR(1) NOT NULL PRIMARY KEY, val VARCHAR(10))');
19$db->exec("INSERT INTO test VALUES('A', 'A')");
20$db->exec("INSERT INTO test VALUES('B', 'A')");
21$db->exec("INSERT INTO test VALUES('C', 'C')");
22
23$stmt = $db->prepare('SELECT id, val from test');
24
25$stmt->execute();
26var_dump($stmt->fetchAll(PDO::FETCH_NUM|PDO::FETCH_UNIQUE));
27
28$stmt->execute();
29var_dump($stmt->fetchAll(PDO::FETCH_ASSOC|PDO::FETCH_UNIQUE));
30
31?>
32--EXPECT--
33array(3) {
34  ["A"]=>
35  array(1) {
36    [0]=>
37    string(1) "A"
38  }
39  ["B"]=>
40  array(1) {
41    [0]=>
42    string(1) "A"
43  }
44  ["C"]=>
45  array(1) {
46    [0]=>
47    string(1) "C"
48  }
49}
50array(3) {
51  ["A"]=>
52  array(1) {
53    ["val"]=>
54    string(1) "A"
55  }
56  ["B"]=>
57  array(1) {
58    ["val"]=>
59    string(1) "A"
60  }
61  ["C"]=>
62  array(1) {
63    ["val"]=>
64    string(1) "C"
65  }
66}
67