1--TEST-- 2PDO::ATTR_CASE 3--EXTENSIONS-- 4pdo_mysql 5--SKIPIF-- 6<?php 7require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); 8MySQLPDOTest::skip(); 9$db = MySQLPDOTest::factory(); 10?> 11--FILE-- 12<?php 13 require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); 14 $db = MySQLPDOTest::factory(); 15 $db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); 16 MySQLPDOTest::createTestTable($db); 17 18 $default = $db->getAttribute(PDO::ATTR_CASE); 19 $known = array( 20 PDO::CASE_LOWER => 'PDO::CASE_LOWER', 21 PDO::CASE_UPPER => 'PDO::CASE_UPPER', 22 PDO::CASE_NATURAL => 'PDO::CASE_NATURAL' 23 ); 24 if (!isset($known[$default])) 25 printf("[001] getAttribute(PDO::ATTR_CASE) returns unknown value '%s'\n", 26 var_export($default, true)); 27 else 28 var_dump($known[$default]); 29 30 // lets see what the default is... 31 if (!is_object($stmt = $db->query("SELECT id, id AS 'ID_UPPER', label FROM test ORDER BY id ASC LIMIT 2"))) 32 printf("[002] %s - %s\n", 33 var_export($db->errorInfo(), true), var_export($db->errorCode(), true)); 34 35 var_dump($stmt->fetchAll(PDO::FETCH_BOTH)); 36 37 if (true !== $db->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER)) 38 printf("[003] Cannot set PDO::ATTR_CASE = PDO::CASE_LOWER, %s - %s\n", 39 var_export($db->errorInfo(), true), var_export($db->errorCode(), true)); 40 41 if (($tmp = $db->getAttribute(PDO::ATTR_CASE)) !== PDO::CASE_LOWER) 42 printf("[004] getAttribute(PDO::ATTR_CASE) returns wrong value '%s'\n", 43 var_export($tmp, true)); 44 45 if (true === $db->exec('ALTER TABLE test ADD MiXeD CHAR(1)')) 46 printf("[005] Cannot add column %s - %s\n", 47 var_export($db->errorInfo(), true), var_export($db->errorCode(), true)); 48 49 if (false === $db->exec('ALTER TABLE test ADD MYUPPER CHAR(1)')) 50 printf("[006] Cannot add column %s - %s\n", 51 var_export($db->errorInfo(), true), var_export($db->errorCode(), true)); 52 53 if (!is_object($stmt = $db->query("SELECT id, id AS 'ID_UPPER', label, MiXeD, MYUPPER FROM test ORDER BY id ASC LIMIT 2"))) 54 printf("[007] %s - %s\n", 55 var_export($db->errorInfo(), true), var_export($db->errorCode(), true)); 56 57 var_dump($stmt->fetchAll(PDO::FETCH_BOTH)); 58 59 if (true !== $db->setAttribute(PDO::ATTR_CASE, PDO::CASE_UPPER)) 60 printf("[008] Cannot set PDO::ATTR_CASE = PDO::CASE_UPPER %s - %s\n", 61 var_export($db->errorInfo(), true), var_export($db->errorCode(), true)); 62 63 if (($tmp = $db->getAttribute(PDO::ATTR_CASE)) !== PDO::CASE_UPPER) 64 printf("[009] getAttribute(PDO::ATTR_CASE) returns wrong value '%s'\n", 65 var_export($tmp, true)); 66 67 if (!is_object($stmt = $db->query("SELECT id, label, MiXeD, MYUPPER, MYUPPER AS 'lower' FROM test ORDER BY id ASC LIMIT 1"))) 68 printf("[010] %s - %s\n", 69 var_export($db->errorInfo(), true), var_export($db->errorCode(), true)); 70 71 var_dump($stmt->fetchAll(PDO::FETCH_BOTH)); 72 73 if (true !== $db->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL)) 74 printf("[011] Cannot set PDO::ATTR_CASE = PDO::CASE_NATURAL %s - %s\n", 75 var_export($db->errorInfo(), true), var_export($db->errorCode(), true)); 76 77 if (($tmp = $db->getAttribute(PDO::ATTR_CASE)) !== PDO::CASE_NATURAL) 78 printf("[012] getAttribute(PDO::ATTR_CASE) returns wrong value '%s'\n", 79 var_export($tmp, true)); 80 81 if (!is_object($stmt = $db->query("SELECT id, label, MiXeD, MYUPPER, id AS 'ID' FROM test ORDER BY id ASC LIMIT 1"))) 82 printf("[013] %s - %s\n", 83 var_export($db->errorInfo(), true), var_export($db->errorCode(), true)); 84 85 var_dump($stmt->fetchAll(PDO::FETCH_BOTH)); 86 87 print "done!"; 88?> 89--CLEAN-- 90<?php 91require __DIR__ . '/mysql_pdo_test.inc'; 92MySQLPDOTest::dropTestTable(); 93?> 94--EXPECT-- 95string(15) "PDO::CASE_LOWER" 96array(2) { 97 [0]=> 98 array(6) { 99 ["id"]=> 100 string(1) "1" 101 [0]=> 102 string(1) "1" 103 ["id_upper"]=> 104 string(1) "1" 105 [1]=> 106 string(1) "1" 107 ["label"]=> 108 string(1) "a" 109 [2]=> 110 string(1) "a" 111 } 112 [1]=> 113 array(6) { 114 ["id"]=> 115 string(1) "2" 116 [0]=> 117 string(1) "2" 118 ["id_upper"]=> 119 string(1) "2" 120 [1]=> 121 string(1) "2" 122 ["label"]=> 123 string(1) "b" 124 [2]=> 125 string(1) "b" 126 } 127} 128array(2) { 129 [0]=> 130 array(10) { 131 ["id"]=> 132 string(1) "1" 133 [0]=> 134 string(1) "1" 135 ["id_upper"]=> 136 string(1) "1" 137 [1]=> 138 string(1) "1" 139 ["label"]=> 140 string(1) "a" 141 [2]=> 142 string(1) "a" 143 ["mixed"]=> 144 NULL 145 [3]=> 146 NULL 147 ["myupper"]=> 148 NULL 149 [4]=> 150 NULL 151 } 152 [1]=> 153 array(10) { 154 ["id"]=> 155 string(1) "2" 156 [0]=> 157 string(1) "2" 158 ["id_upper"]=> 159 string(1) "2" 160 [1]=> 161 string(1) "2" 162 ["label"]=> 163 string(1) "b" 164 [2]=> 165 string(1) "b" 166 ["mixed"]=> 167 NULL 168 [3]=> 169 NULL 170 ["myupper"]=> 171 NULL 172 [4]=> 173 NULL 174 } 175} 176array(1) { 177 [0]=> 178 array(10) { 179 ["ID"]=> 180 string(1) "1" 181 [0]=> 182 string(1) "1" 183 ["LABEL"]=> 184 string(1) "a" 185 [1]=> 186 string(1) "a" 187 ["MIXED"]=> 188 NULL 189 [2]=> 190 NULL 191 ["MYUPPER"]=> 192 NULL 193 [3]=> 194 NULL 195 ["LOWER"]=> 196 NULL 197 [4]=> 198 NULL 199 } 200} 201array(1) { 202 [0]=> 203 array(10) { 204 ["id"]=> 205 string(1) "1" 206 [0]=> 207 string(1) "1" 208 ["label"]=> 209 string(1) "a" 210 [1]=> 211 string(1) "a" 212 ["MiXeD"]=> 213 NULL 214 [2]=> 215 NULL 216 ["MYUPPER"]=> 217 NULL 218 [3]=> 219 NULL 220 ["ID"]=> 221 string(1) "1" 222 [4]=> 223 string(1) "1" 224 } 225} 226done! 227