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