mysqli_num_fields.phpt 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. --TEST--
  2. mysqli_num_fields()
  3. --SKIPIF--
  4. <?php
  5. require_once('skipif.inc');
  6. require_once('skipifemb.inc');
  7. require_once('skipifconnectfailure.inc');
  8. ?>
  9. --FILE--
  10. <?php
  11. require_once("connect.inc");
  12. $tmp = NULL;
  13. $link = NULL;
  14. if (!is_null($tmp = @mysqli_num_fields()))
  15. printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  16. if (!is_null($tmp = @mysqli_num_fields($link)))
  17. printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  18. require('table.inc');
  19. function func_test_mysqli_num_fields($link, $query, $expected, $offset, $test_free = false) {
  20. if (!($res = mysqli_query($link, $query))) {
  21. printf("[%03d] [%d] %s\n", $offset, mysqli_errno($link), mysqli_error($link));
  22. return;
  23. }
  24. if ($expected !== ($tmp = mysqli_num_fields($res)))
  25. printf("[%03d] Expecting %s/%d, got %s/%d\n", $offset + 1,
  26. gettype($expected), $expected,
  27. gettype($tmp), $tmp);
  28. mysqli_free_result($res);
  29. if ($test_free && (NULL !== ($tmp = mysqli_num_fields($res))))
  30. printf("[%03d] Expecting NULL, got %s/%s\n", $offset + 2, gettype($tmp), $tmp);
  31. }
  32. func_test_mysqli_num_fields($link, "SELECT 1 AS a", 1, 5);
  33. func_test_mysqli_num_fields($link, "SELECT id, label FROM test", 2, 10);
  34. func_test_mysqli_num_fields($link, "SELECT 1 AS a, NULL AS b, 'foo' AS c", 3, 15);
  35. func_test_mysqli_num_fields($link, "SELECT id FROM test", 1, 20, true);
  36. mysqli_close($link);
  37. print "done!";
  38. ?>
  39. --CLEAN--
  40. <?php
  41. require_once("clean_table.inc");
  42. ?>
  43. --EXPECTF--
  44. Warning: mysqli_num_fields(): Couldn't fetch mysqli_result in %s on line %d
  45. done!