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