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