mysqli_fetch_fields.phpt 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. --TEST--
  2. mysqli_fetch_fields()
  3. --EXTENSIONS--
  4. mysqli
  5. --SKIPIF--
  6. <?php
  7. require_once('skipifconnectfailure.inc');
  8. ?>
  9. --FILE--
  10. <?php
  11. require_once("connect.inc");
  12. // Note: no SQL type tests, internally the same function gets used as for mysqli_fetch_array() which does a lot of SQL type test
  13. require('table.inc');
  14. // Make sure that client, connection and result charsets are all the
  15. // same. Not sure whether this is strictly necessary.
  16. if (!mysqli_set_charset($link, 'utf8'))
  17. printf("[%d] %s\n", mysqli_errno($link), mysqli_errno($link));
  18. $charsetInfo = mysqli_get_charset($link);
  19. if (!$res = mysqli_query($link, "SELECT id AS ID, label FROM test AS TEST ORDER BY id LIMIT 1")) {
  20. printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  21. }
  22. $fields = mysqli_fetch_fields($res);
  23. foreach ($fields as $k => $field) {
  24. var_dump($field);
  25. switch ($k) {
  26. case 1:
  27. /* label column, result set charset */
  28. if ($field->charsetnr != $charsetInfo->number) {
  29. printf("[004] Expecting charset %s/%d got %d\n",
  30. $charsetInfo->charset,
  31. $charsetInfo->number, $field->charsetnr);
  32. }
  33. break;
  34. }
  35. }
  36. mysqli_free_result($res);
  37. try {
  38. mysqli_fetch_fields($res);
  39. } catch (Error $exception) {
  40. echo $exception->getMessage() . "\n";
  41. }
  42. mysqli_close($link);
  43. print "done!";
  44. ?>
  45. --CLEAN--
  46. <?php
  47. require_once("clean_table.inc");
  48. ?>
  49. --EXPECTF--
  50. object(stdClass)#%d (13) {
  51. ["name"]=>
  52. string(2) "ID"
  53. ["orgname"]=>
  54. string(2) "id"
  55. ["table"]=>
  56. string(4) "TEST"
  57. ["orgtable"]=>
  58. string(%d) "%s"
  59. ["def"]=>
  60. string(0) ""
  61. ["db"]=>
  62. string(%d) "%s"
  63. ["catalog"]=>
  64. string(%d) "%s"
  65. ["max_length"]=>
  66. int(0)
  67. ["length"]=>
  68. int(11)
  69. ["charsetnr"]=>
  70. int(63)
  71. ["flags"]=>
  72. int(49155)
  73. ["type"]=>
  74. int(3)
  75. ["decimals"]=>
  76. int(0)
  77. }
  78. object(stdClass)#%d (13) {
  79. ["name"]=>
  80. string(5) "label"
  81. ["orgname"]=>
  82. string(5) "label"
  83. ["table"]=>
  84. string(4) "TEST"
  85. ["orgtable"]=>
  86. string(%d) "%s"
  87. ["def"]=>
  88. string(0) ""
  89. ["db"]=>
  90. string(%d) "%s"
  91. ["catalog"]=>
  92. string(%d) "%s"
  93. ["max_length"]=>
  94. int(0)
  95. ["length"]=>
  96. int(%d)
  97. ["charsetnr"]=>
  98. int(%d)
  99. ["flags"]=>
  100. int(0)
  101. ["type"]=>
  102. int(254)
  103. ["decimals"]=>
  104. int(0)
  105. }
  106. mysqli_result object is already closed
  107. done!