1--TEST-- 2mysqli_stmt_get_result() - meta data, field info 3--EXTENSIONS-- 4mysqli 5--SKIPIF-- 6<?php 7require_once 'skipifconnectfailure.inc'; 8?> 9--FILE-- 10<?php 11 require 'table.inc'; 12 13 // Make sure that client, connection and result charsets are all the 14 // same. Not sure whether this is strictly necessary. 15 if (!mysqli_set_charset($link, 'utf8')) 16 printf("[%d] %s\n", mysqli_errno($link), mysqli_errno($link)); 17 18 $charsetInfo = mysqli_get_charset($link); 19 20 if (!($stmt = mysqli_stmt_init($link)) || 21 !mysqli_stmt_prepare($stmt, "SELECT id, label, id + 1 as _id, concat(label, '_') ___label FROM test ORDER BY id ASC LIMIT 3") || 22 !mysqli_stmt_execute($stmt)) 23 printf("[001] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 24 25 if (!is_object($res = mysqli_stmt_get_result($stmt)) || 'mysqli_result' != get_class($res)) { 26 printf("[002] Expecting object/mysqli_result got %s/%s, [%d] %s\n", 27 gettype($res), $res, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 28 } 29 30 if (!is_object($res_meta = mysqli_stmt_result_metadata($stmt)) || 31 'mysqli_result' != get_class($res_meta)) { 32 printf("[003] Expecting object/mysqli_result got %s/%s, [%d] %s\n", 33 gettype($res), $res, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 34 } 35 36 $i = 0; 37 while ($field = $res->fetch_field()) { 38 var_dump($field); 39 $i++; 40 if (2 == $i) { 41 /* 42 Label column, result set charset. 43 All of the following columns are "too hot" - too server dependent 44 */ 45 if ($field->charsetnr != $charsetInfo->number) { 46 printf("[004] Expecting charset %s/%d got %d\n", 47 $charsetInfo->charset, 48 $charsetInfo->number, $field->charsetnr); 49 } 50 if ($field->length != $charsetInfo->max_length) { 51 printf("[005] Expecting length %d got %d\n", 52 $charsetInfo->max_length, $field->max_length); 53 } 54 } 55 } 56 57 mysqli_stmt_close($stmt); 58 mysqli_close($link); 59 print "done!"; 60?> 61--CLEAN-- 62<?php 63 require_once 'clean_table.inc'; 64?> 65--EXPECTF-- 66object(stdClass)#%d (13) { 67 ["name"]=> 68 string(2) "id" 69 ["orgname"]=> 70 string(2) "id" 71 ["table"]=> 72 string(4) "test" 73 ["orgtable"]=> 74 string(4) "test" 75 ["def"]=> 76 string(0) "" 77 ["db"]=> 78 string(%d) "%s" 79 ["catalog"]=> 80 string(%d) "%s" 81 ["max_length"]=> 82 int(0) 83 ["length"]=> 84 int(11) 85 ["charsetnr"]=> 86 int(63) 87 ["flags"]=> 88 int(49155) 89 ["type"]=> 90 int(3) 91 ["decimals"]=> 92 int(0) 93} 94object(stdClass)#%d (13) { 95 ["name"]=> 96 string(5) "label" 97 ["orgname"]=> 98 string(5) "label" 99 ["table"]=> 100 string(4) "test" 101 ["orgtable"]=> 102 string(4) "test" 103 ["def"]=> 104 string(0) "" 105 ["db"]=> 106 string(%d) "%s" 107 ["catalog"]=> 108 string(%d) "%s" 109 ["max_length"]=> 110 int(%d) 111 ["length"]=> 112 int(%d) 113 ["charsetnr"]=> 114 int(%d) 115 ["flags"]=> 116 int(0) 117 ["type"]=> 118 int(254) 119 ["decimals"]=> 120 int(0) 121} 122object(stdClass)#%d (13) { 123 ["name"]=> 124 string(3) "_id" 125 ["orgname"]=> 126 string(0) "" 127 ["table"]=> 128 string(0) "" 129 ["orgtable"]=> 130 string(0) "" 131 ["def"]=> 132 string(0) "" 133 ["db"]=> 134 string(0) "" 135 ["catalog"]=> 136 string(%d) "%s" 137 ["max_length"]=> 138 int(0) 139 ["length"]=> 140 int(%d) 141 ["charsetnr"]=> 142 int(63) 143 ["flags"]=> 144 int(32897) 145 ["type"]=> 146 int(8) 147 ["decimals"]=> 148 int(0) 149} 150object(stdClass)#%d (13) { 151 ["name"]=> 152 string(8) "___label" 153 ["orgname"]=> 154 string(0) "" 155 ["table"]=> 156 string(0) "" 157 ["orgtable"]=> 158 string(0) "" 159 ["def"]=> 160 string(0) "" 161 ["db"]=> 162 string(0) "" 163 ["catalog"]=> 164 string(%d) "%s" 165 ["max_length"]=> 166 int(%d) 167 ["length"]=> 168 int(%d) 169 ["charsetnr"]=> 170 int(%d) 171 ["flags"]=> 172 int(0) 173 ["type"]=> 174 int(253) 175 ["decimals"]=> 176 int(3%d) 177} 178done! 179