mysql_num_fields.phpt 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. --TEST--
  2. mysql_num_fields()
  3. --SKIPIF--
  4. <?php
  5. require_once('skipif.inc');
  6. require_once('skipifconnectfailure.inc');
  7. ?>
  8. --FILE--
  9. <?php
  10. include "connect.inc";
  11. $tmp = NULL;
  12. $link = NULL;
  13. if (!is_null($tmp = @mysql_num_fields()))
  14. printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  15. if (NULL !== ($tmp = @mysql_num_fields($link)))
  16. printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  17. require('table.inc');
  18. function func_test_mysql_num_fields($link, $query, $expected, $offset, $test_free = false) {
  19. if (!($res = mysql_query($query, $link))) {
  20. printf("[%03d] [%d] %s\n", $offset, mysql_errno($link), mysql_error($link));
  21. return;
  22. }
  23. if ($expected !== ($tmp = mysql_num_fields($res)))
  24. printf("[%03d] Expecting %s/%d, got %s/%d\n", $offset + 1,
  25. gettype($expected), $expected,
  26. gettype($tmp), $tmp);
  27. mysql_free_result($res);
  28. if ($test_free && (false !== ($tmp = mysql_num_fields($res))))
  29. printf("[%03d] Expecting boolean/false, got %s/%s\n", $offset + 2, gettype($tmp), $tmp);
  30. }
  31. func_test_mysql_num_fields($link, "SELECT 1 AS a", 1, 5);
  32. func_test_mysql_num_fields($link, "SELECT id, label FROM test", 2, 10);
  33. func_test_mysql_num_fields($link, "SELECT 1 AS a, NULL AS b, 'foo' AS c", 3, 15);
  34. func_test_mysql_num_fields($link, "SELECT id FROM test", 1, 20, true);
  35. mysql_close($link);
  36. print "done!";
  37. ?>
  38. --CLEAN--
  39. <?php
  40. require_once("clean_table.inc");
  41. ?>
  42. --EXPECTF--
  43. Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d
  44. Warning: mysql_num_fields(): %d is not a valid MySQL result resource in %s on line %d
  45. done!