xref: /PHP-8.3/ext/pdo/tests/pdo_032.phpt (revision 74859783)
1--TEST--
2PDO Common: PDO::ATTR_CASE
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, 'B')");
21$db->exec("INSERT INTO test VALUES(3, 'C')");
22
23// Lower case columns
24$db->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
25$stmt = $db->prepare('SELECT * from test');
26$stmt->execute();
27var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
28$stmt->closeCursor();
29
30// Upper case columns
31$db->setAttribute(PDO::ATTR_CASE, PDO::CASE_UPPER);
32$stmt = $db->prepare('SELECT * from test');
33$stmt->execute();
34var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
35$stmt->closeCursor();
36
37?>
38--EXPECT--
39array(3) {
40  [0]=>
41  array(2) {
42    ["id"]=>
43    string(1) "1"
44    ["val"]=>
45    string(1) "A"
46  }
47  [1]=>
48  array(2) {
49    ["id"]=>
50    string(1) "2"
51    ["val"]=>
52    string(1) "B"
53  }
54  [2]=>
55  array(2) {
56    ["id"]=>
57    string(1) "3"
58    ["val"]=>
59    string(1) "C"
60  }
61}
62array(3) {
63  [0]=>
64  array(2) {
65    ["ID"]=>
66    string(1) "1"
67    ["VAL"]=>
68    string(1) "A"
69  }
70  [1]=>
71  array(2) {
72    ["ID"]=>
73    string(1) "2"
74    ["VAL"]=>
75    string(1) "B"
76  }
77  [2]=>
78  array(2) {
79    ["ID"]=>
80    string(1) "3"
81    ["VAL"]=>
82    string(1) "C"
83  }
84}
85