mysqli_fetch_field.phpt 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. --TEST--
  2. mysqli_fetch_field()
  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. /* ID column, binary charset */
  23. $tmp = mysqli_fetch_field($res);
  24. var_dump($tmp);
  25. /* label column, result set charset */
  26. $tmp = mysqli_fetch_field($res);
  27. var_dump($tmp);
  28. if ($tmp->charsetnr != $charsetInfo->number) {
  29. printf("[004] Expecting charset %s/%d got %d\n",
  30. $charsetInfo->charset, $charsetInfo->number, $tmp->charsetnr);
  31. }
  32. if ($tmp->db != $db) {
  33. printf("011] Expecting database '%s' got '%s'\n",
  34. $db, $tmp->db);
  35. }
  36. var_dump(mysqli_fetch_field($res));
  37. mysqli_free_result($res);
  38. // Read http://bugs.php.net/bug.php?id=42344 on defaults!
  39. try {
  40. mysqli_fetch_field($res);
  41. } catch (Error $exception) {
  42. echo $exception->getMessage() . "\n";
  43. }
  44. if (!mysqli_query($link, "DROP TABLE IF EXISTS test"))
  45. printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  46. if (!mysqli_query($link, "CREATE TABLE test(id INT NOT NULL DEFAULT 1)"))
  47. printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  48. if (!mysqli_query($link, "INSERT INTO test(id) VALUES (2)"))
  49. printf("[009] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  50. if (!$res = mysqli_query($link, "SELECT id as _default_test FROM test")) {
  51. printf("[010] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  52. }
  53. var_dump(mysqli_fetch_assoc($res));
  54. /* binary */
  55. var_dump(mysqli_fetch_field($res));
  56. mysqli_free_result($res);
  57. mysqli_close($link);
  58. print "done!";
  59. ?>
  60. --CLEAN--
  61. <?php
  62. require_once("clean_table.inc");
  63. ?>
  64. --EXPECTF--
  65. object(stdClass)#%d (13) {
  66. ["name"]=>
  67. string(2) "ID"
  68. ["orgname"]=>
  69. string(2) "id"
  70. ["table"]=>
  71. string(4) "TEST"
  72. ["orgtable"]=>
  73. string(%d) "%s"
  74. ["def"]=>
  75. string(0) ""
  76. ["db"]=>
  77. string(%d) "%s"
  78. ["catalog"]=>
  79. string(%d) "%s"
  80. ["max_length"]=>
  81. int(0)
  82. ["length"]=>
  83. int(11)
  84. ["charsetnr"]=>
  85. int(63)
  86. ["flags"]=>
  87. int(49155)
  88. ["type"]=>
  89. int(3)
  90. ["decimals"]=>
  91. int(0)
  92. }
  93. object(stdClass)#%d (13) {
  94. ["name"]=>
  95. string(5) "label"
  96. ["orgname"]=>
  97. string(5) "label"
  98. ["table"]=>
  99. string(4) "TEST"
  100. ["orgtable"]=>
  101. string(%d) "%s"
  102. ["def"]=>
  103. string(0) ""
  104. ["db"]=>
  105. string(%d) "%s"
  106. ["catalog"]=>
  107. string(%d) "%s"
  108. ["max_length"]=>
  109. int(%d)
  110. ["length"]=>
  111. int(%d)
  112. ["charsetnr"]=>
  113. int(%d)
  114. ["flags"]=>
  115. int(0)
  116. ["type"]=>
  117. int(254)
  118. ["decimals"]=>
  119. int(0)
  120. }
  121. bool(false)
  122. mysqli_result object is already closed
  123. array(1) {
  124. ["_default_test"]=>
  125. string(1) "2"
  126. }
  127. object(stdClass)#%d (13) {
  128. ["name"]=>
  129. string(13) "_default_test"
  130. ["orgname"]=>
  131. string(2) "id"
  132. ["table"]=>
  133. string(%d) "%s"
  134. ["orgtable"]=>
  135. string(%d) "%s"
  136. ["def"]=>
  137. string(0) ""
  138. ["db"]=>
  139. string(%d) "%s"
  140. ["catalog"]=>
  141. string(%d) "%s"
  142. ["max_length"]=>
  143. int(0)
  144. ["length"]=>
  145. int(11)
  146. ["charsetnr"]=>
  147. int(63)
  148. ["flags"]=>
  149. int(32769)
  150. ["type"]=>
  151. int(3)
  152. ["decimals"]=>
  153. int(0)
  154. }
  155. done!