1--TEST-- 2mysqli_num_fields() 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_num_fields())) 17 printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); 18 19 if (!is_null($tmp = @mysqli_num_fields($link))) 20 printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); 21 22 require('table.inc'); 23 24 function func_test_mysqli_num_fields($link, $query, $expected, $offset, $test_free = false) { 25 26 if (!($res = mysqli_query($link, $query))) { 27 printf("[%03d] [%d] %s\n", $offset, mysqli_errno($link), mysqli_error($link)); 28 return; 29 } 30 31 if ($expected !== ($tmp = mysqli_num_fields($res))) 32 printf("[%03d] Expecting %s/%d, got %s/%d\n", $offset + 1, 33 gettype($expected), $expected, 34 gettype($tmp), $tmp); 35 36 mysqli_free_result($res); 37 38 if ($test_free && (NULL !== ($tmp = mysqli_num_fields($res)))) 39 printf("[%03d] Expecting NULL, got %s/%s\n", $offset + 2, gettype($tmp), $tmp); 40 } 41 42 func_test_mysqli_num_fields($link, "SELECT 1 AS a", 1, 5); 43 func_test_mysqli_num_fields($link, "SELECT id, label FROM test", 2, 10); 44 func_test_mysqli_num_fields($link, "SELECT 1 AS a, NULL AS b, 'foo' AS c", 3, 15); 45 func_test_mysqli_num_fields($link, "SELECT id FROM test", 1, 20, true); 46 47 mysqli_close($link); 48 49 print "done!"; 50?> 51--CLEAN-- 52<?php 53 require_once("clean_table.inc"); 54?> 55--EXPECTF-- 56Warning: mysqli_num_fields(): Couldn't fetch mysqli_result in %s on line %d 57done! 58