047.phpt 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. --TEST--
  2. mysqli_stmt_result_metadata
  3. --SKIPIF--
  4. <?php
  5. require_once('skipif.inc');
  6. require_once('skipifconnectfailure.inc');
  7. ?>
  8. --FILE--
  9. <?php
  10. require_once("connect.inc");
  11. /*** test mysqli_connect 127.0.0.1 ***/
  12. $link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
  13. mysqli_select_db($link, $db);
  14. mysqli_query($link, "DROP TABLE IF EXISTS test_affected");
  15. mysqli_query($link, "CREATE TABLE test_affected (foo int, bar varchar(10) character set latin1) ENGINE=" . $engine);
  16. mysqli_query($link, "INSERT INTO test_affected VALUES (1, 'Zak'),(2, 'Greant')");
  17. $stmt = mysqli_prepare($link, "SELECT * FROM test_affected");
  18. mysqli_stmt_execute($stmt);
  19. $result = mysqli_stmt_result_metadata($stmt);
  20. echo "\n=== fetch_fields ===\n";
  21. var_dump(mysqli_fetch_fields($result));
  22. echo "\n=== fetch_field_direct ===\n";
  23. var_dump(mysqli_fetch_field_direct($result, 0));
  24. var_dump(mysqli_fetch_field_direct($result, 1));
  25. echo "\n=== fetch_field ===\n";
  26. while ($field = mysqli_fetch_field($result)) {
  27. var_dump($field);
  28. }
  29. print_r(mysqli_fetch_lengths($result));
  30. mysqli_free_result($result);
  31. mysqli_stmt_close($stmt);
  32. mysqli_query($link, "DROP TABLE IF EXISTS test_affected");
  33. mysqli_close($link);
  34. print "done!";
  35. ?>
  36. --CLEAN--
  37. <?php
  38. require_once("connect.inc");
  39. if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
  40. printf("[c001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
  41. if (!mysqli_query($link, "DROP TABLE IF EXISTS test_affected"))
  42. printf("[c002] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  43. mysqli_close($link);
  44. ?>
  45. --EXPECTF--
  46. === fetch_fields ===
  47. array(2) {
  48. [0]=>
  49. object(stdClass)#5 (13) {
  50. [%u|b%"name"]=>
  51. %unicode|string%(3) "foo"
  52. [%u|b%"orgname"]=>
  53. %unicode|string%(3) "foo"
  54. [%u|b%"table"]=>
  55. %unicode|string%(13) "test_affected"
  56. [%u|b%"orgtable"]=>
  57. %unicode|string%(13) "test_affected"
  58. [%u|b%"def"]=>
  59. %unicode|string%(0) ""
  60. [%u|b%"db"]=>
  61. %unicode|string%(%d) "%s"
  62. [%u|b%"catalog"]=>
  63. %unicode|string%(%d) "%s"
  64. [%u|b%"max_length"]=>
  65. int(0)
  66. [%u|b%"length"]=>
  67. int(%d)
  68. [%u|b%"charsetnr"]=>
  69. int(%d)
  70. [%u|b%"flags"]=>
  71. int(32768)
  72. [%u|b%"type"]=>
  73. int(3)
  74. [%u|b%"decimals"]=>
  75. int(0)
  76. }
  77. [1]=>
  78. object(stdClass)#6 (13) {
  79. [%u|b%"name"]=>
  80. %unicode|string%(3) "bar"
  81. [%u|b%"orgname"]=>
  82. %unicode|string%(3) "bar"
  83. [%u|b%"table"]=>
  84. %unicode|string%(13) "test_affected"
  85. [%u|b%"orgtable"]=>
  86. %unicode|string%(13) "test_affected"
  87. [%u|b%"def"]=>
  88. %unicode|string%(0) ""
  89. [%u|b%"db"]=>
  90. %unicode|string%(%d) "%s"
  91. [%u|b%"catalog"]=>
  92. %unicode|string%(%d) "%s"
  93. [%u|b%"max_length"]=>
  94. int(0)
  95. [%u|b%"length"]=>
  96. int(%d)
  97. [%u|b%"charsetnr"]=>
  98. int(%d)
  99. [%u|b%"flags"]=>
  100. int(0)
  101. [%u|b%"type"]=>
  102. int(253)
  103. [%u|b%"decimals"]=>
  104. int(0)
  105. }
  106. }
  107. === fetch_field_direct ===
  108. object(stdClass)#6 (13) {
  109. [%u|b%"name"]=>
  110. %unicode|string%(3) "foo"
  111. [%u|b%"orgname"]=>
  112. %unicode|string%(3) "foo"
  113. [%u|b%"table"]=>
  114. %unicode|string%(13) "test_affected"
  115. [%u|b%"orgtable"]=>
  116. %unicode|string%(13) "test_affected"
  117. [%u|b%"def"]=>
  118. %unicode|string%(0) ""
  119. [%u|b%"db"]=>
  120. %unicode|string%(%d) "%s"
  121. [%u|b%"catalog"]=>
  122. %unicode|string%(%d) "%s"
  123. [%u|b%"max_length"]=>
  124. int(0)
  125. [%u|b%"length"]=>
  126. int(%d)
  127. [%u|b%"charsetnr"]=>
  128. int(%d)
  129. [%u|b%"flags"]=>
  130. int(32768)
  131. [%u|b%"type"]=>
  132. int(3)
  133. [%u|b%"decimals"]=>
  134. int(0)
  135. }
  136. object(stdClass)#6 (13) {
  137. [%u|b%"name"]=>
  138. %unicode|string%(3) "bar"
  139. [%u|b%"orgname"]=>
  140. %unicode|string%(3) "bar"
  141. [%u|b%"table"]=>
  142. %unicode|string%(13) "test_affected"
  143. [%u|b%"orgtable"]=>
  144. %unicode|string%(13) "test_affected"
  145. [%u|b%"def"]=>
  146. %unicode|string%(0) ""
  147. [%u|b%"db"]=>
  148. %unicode|string%(%d) "%s"
  149. [%u|b%"catalog"]=>
  150. %unicode|string%(%d) "%s"
  151. [%u|b%"max_length"]=>
  152. int(0)
  153. [%u|b%"length"]=>
  154. int(%d)
  155. [%u|b%"charsetnr"]=>
  156. int(%d)
  157. [%u|b%"flags"]=>
  158. int(0)
  159. [%u|b%"type"]=>
  160. int(253)
  161. [%u|b%"decimals"]=>
  162. int(0)
  163. }
  164. === fetch_field ===
  165. object(stdClass)#6 (13) {
  166. [%u|b%"name"]=>
  167. %unicode|string%(3) "foo"
  168. [%u|b%"orgname"]=>
  169. %unicode|string%(3) "foo"
  170. [%u|b%"table"]=>
  171. %unicode|string%(13) "test_affected"
  172. [%u|b%"orgtable"]=>
  173. %unicode|string%(13) "test_affected"
  174. [%u|b%"def"]=>
  175. %unicode|string%(0) ""
  176. [%u|b%"db"]=>
  177. %unicode|string%(%d) "%s"
  178. [%u|b%"catalog"]=>
  179. %unicode|string%(%d) "%s"
  180. [%u|b%"max_length"]=>
  181. int(0)
  182. [%u|b%"length"]=>
  183. int(%d)
  184. [%u|b%"charsetnr"]=>
  185. int(%d)
  186. [%u|b%"flags"]=>
  187. int(32768)
  188. [%u|b%"type"]=>
  189. int(3)
  190. [%u|b%"decimals"]=>
  191. int(0)
  192. }
  193. object(stdClass)#5 (13) {
  194. [%u|b%"name"]=>
  195. %unicode|string%(3) "bar"
  196. [%u|b%"orgname"]=>
  197. %unicode|string%(3) "bar"
  198. [%u|b%"table"]=>
  199. %unicode|string%(13) "test_affected"
  200. [%u|b%"orgtable"]=>
  201. %unicode|string%(13) "test_affected"
  202. [%u|b%"def"]=>
  203. %unicode|string%(0) ""
  204. [%u|b%"db"]=>
  205. %unicode|string%(%d) "%s"
  206. [%u|b%"catalog"]=>
  207. %unicode|string%(%d) "%s"
  208. [%u|b%"max_length"]=>
  209. int(0)
  210. [%u|b%"length"]=>
  211. int(%d)
  212. [%u|b%"charsetnr"]=>
  213. int(%d)
  214. [%u|b%"flags"]=>
  215. int(0)
  216. [%u|b%"type"]=>
  217. int(253)
  218. [%u|b%"decimals"]=>
  219. int(0)
  220. }
  221. done!