1--TEST-- 2mysqli_stmt_result_metadata() 3--SKIPIF-- 4<?php 5require_once('skipif.inc'); 6require_once('skipifemb.inc'); 7require_once('skipifconnectfailure.inc'); 8?> 9--FILE-- 10<?php 11 require_once("connect.inc"); 12 13 $tmp = NULL; 14 $link = NULL; 15 16 if (!is_null($tmp = @mysqli_stmt_result_metadata())) 17 printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); 18 19 if (!is_null($tmp = @mysqli_stmt_result_metadata($link))) 20 printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); 21 22 require('table.inc'); 23 24 if (!$stmt = mysqli_stmt_init($link)) 25 printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 26 27 if (false !== ($tmp = mysqli_stmt_result_metadata($stmt))) 28 printf("[004] Expecting false, got %s/%s\n", gettype($tmp), $tmp); 29 30 if (!mysqli_stmt_prepare($stmt, "SELECT id, label FROM test")) 31 printf("[005] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 32 33 if (!is_object(($res = mysqli_stmt_result_metadata($stmt)))) 34 printf("[006] Expecting object, got %s/%s\n", gettype($tmp), $tmp); 35 36 if (2 !== ($tmp = mysqli_num_fields($res))) 37 printf("[007] Expecting int/2, got %s/%s, [%d] %s\n", 38 gettype($tmp), $tmp, mysqli_errno($link), mysqli_error($link)); 39 40 if (!is_object($field0_fetch = mysqli_fetch_field($res))) 41 printf("[008] Expecting object, got %s/%s, [%d] %s\n", 42 gettype($field0_fetch), $field0_fetch, mysqli_errno($link), mysqli_error($link)); 43 44 if (!is_object($field0_direct = mysqli_fetch_field_direct($res, 0))) 45 printf("[009] Expecting object, got %s/%s, [%d] %s\n", 46 gettype($field0_direct), $field0_direct, mysqli_errno($link), mysqli_error($link)); 47 48 if ($field0_fetch != $field0_direct) { 49 printf("[010] mysqli_fetch_field() differs from mysqli_fetch_field_direct()\n"); 50 var_dump($field0_fetch); 51 var_dump($field0_direct); 52 } 53 54 var_dump($field0_fetch); 55 56 if (!is_array($tmp = mysqli_fetch_fields($res))) 57 printf("[011] Expecting array, got %s/%s, [%d] %s\n", 58 gettype($tmp), $tmp, mysqli_errno($link), mysqli_error($link)); 59 60 if (empty($tmp[0]) || empty($tmp[1]) || $tmp[0] != $field0_direct) { 61 printf("[012] mysqli_fetch_fields() return value is suspicious\n"); 62 var_dump($tmp); 63 } 64 65 if (!mysqli_field_seek($res, 1)) 66 printf("[013] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 67 68 if (!is_object($field1_direct = mysqli_fetch_field_direct($res, 1))) 69 printf("[014] Expecting object, got %s/%s, [%d] %s\n", 70 gettype($field1_direct), $field1_direct, mysqli_errno($link), mysqli_error($link)); 71 72 if ($tmp[1] != $field1_direct) { 73 printf("[015] mysqli_fetch_field_direct() differs from mysqli_fetch_fields()\n"); 74 var_dump($field1_direct); 75 var_dump($tmp); 76 } 77 78 if (1 !== ($tmp = mysqli_field_tell($res))) 79 printf("[016] Expecting int/1, got %s/%s, [%d] %s\n", 80 gettype($tmp), $tmp, mysqli_errno($link), mysqli_error($link)); 81 82 mysqli_free_result($res); 83 mysqli_stmt_close($stmt); 84 85 if (false !== ($tmp = mysqli_stmt_result_metadata($stmt))) 86 printf("[017] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); 87 88 /* Check that the function alias exists. It's a deprecated function, 89 but we have not announce the removal so far, therefore we need to check for it */ 90 if (!is_null($tmp = @mysqli_stmt_result_metadata())) 91 printf("[018] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); 92 93 mysqli_close($link); 94 print "done!"; 95?> 96--CLEAN-- 97<?php 98 require_once("clean_table.inc"); 99?> 100--EXPECTF-- 101Warning: mysqli_stmt_result_metadata(): invalid object or resource mysqli_stmt 102 in %s on line %d 103object(stdClass)#5 (13) { 104 ["name"]=> 105 string(2) "id" 106 ["orgname"]=> 107 string(2) "id" 108 ["table"]=> 109 string(4) "test" 110 ["orgtable"]=> 111 string(4) "test" 112 ["def"]=> 113 string(0) "" 114 ["db"]=> 115 string(%d) "%s" 116 ["catalog"]=> 117 string(%d) "%s" 118 ["max_length"]=> 119 int(0) 120 ["length"]=> 121 int(11) 122 ["charsetnr"]=> 123 int(63) 124 ["flags"]=> 125 int(49155) 126 ["type"]=> 127 int(3) 128 ["decimals"]=> 129 int(0) 130} 131 132Warning: mysqli_stmt_result_metadata(): Couldn't fetch mysqli_stmt in %s on line %d 133done! 134