mysqli_field_seek.phpt 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. --TEST--
  2. mysqli_field_seek()
  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. function mysqli_field_seek_flags($flags) {
  12. $ret = '';
  13. if ($flags & MYSQLI_NOT_NULL_FLAG)
  14. $ret .= 'MYSQLI_NOT_NULL_FLAG ';
  15. if ($flags & MYSQLI_PRI_KEY_FLAG)
  16. $ret .= 'MYSQLI_PRI_KEY_FLAG ';
  17. if ($flags & MYSQLI_UNIQUE_KEY_FLAG)
  18. $ret .= 'MYSQLI_UNIQUE_KEY_FLAG ';
  19. if ($flags & MYSQLI_MULTIPLE_KEY_FLAG)
  20. $ret .= 'MYSQLI_MULTIPLE_KEY_FLAG ';
  21. if ($flags & MYSQLI_BLOB_FLAG)
  22. $ret .= 'MYSQLI_BLOB_FLAG ';
  23. if ($flags & MYSQLI_UNSIGNED_FLAG)
  24. $ret .= 'MYSQLI_UNSIGNED_FLAG ';
  25. if ($flags & MYSQLI_ZEROFILL_FLAG)
  26. $ret .= 'MYSQLI_ZEROFILL_FLAG ';
  27. if ($flags & MYSQLI_AUTO_INCREMENT_FLAG)
  28. $ret .= 'MYSQLI_AUTO_INCREMENT_FLAG ';
  29. if ($flags & MYSQLI_TIMESTAMP_FLAG)
  30. $ret .= 'MYSQLI_TIMESTAMP_FLAG ';
  31. if ($flags & MYSQLI_SET_FLAG)
  32. $ret .= 'MYSQLI_SET_FLAG ';
  33. if ($flags & MYSQLI_NUM_FLAG)
  34. $ret .= 'MYSQLI_NUM_FLAG ';
  35. if ($flags & MYSQLI_PART_KEY_FLAG)
  36. $ret .= 'MYSQLI_PART_KEY_FLAG ';
  37. if ($flags & MYSQLI_GROUP_FLAG)
  38. $ret .= 'MYSQLI_GROUP_FLAG ';
  39. return $ret;
  40. }
  41. require_once("connect.inc");
  42. $tmp = NULL;
  43. $link = NULL;
  44. if (!is_null($tmp = @mysqli_field_seek()))
  45. printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  46. if (!is_null($tmp = @mysqli_field_seek($link)))
  47. printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  48. require('table.inc');
  49. // Make sure that client, connection and result charsets are all the
  50. // same. Not sure whether this is strictly necessary.
  51. if (!mysqli_set_charset($link, 'utf8'))
  52. printf("[%d] %s\n", mysqli_errno($link), mysqli_errno($link));
  53. $charsetInfo = mysqli_get_charset($link);
  54. if (!$res = mysqli_query($link, "SELECT id, label FROM test ORDER BY id LIMIT 1", MYSQLI_USE_RESULT)) {
  55. printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  56. }
  57. var_dump(mysqli_field_seek($res, -1));
  58. var_dump(mysqli_fetch_field($res));
  59. var_dump(mysqli_field_seek($res, 0));
  60. var_dump(mysqli_fetch_field($res));
  61. var_dump(mysqli_field_seek($res, 1));
  62. $field = mysqli_fetch_field($res);
  63. var_dump($field);
  64. /* label column, result set charset */
  65. if ($field->charsetnr != $charsetInfo->number) {
  66. printf("[004] Expecting charset %s/%d got %d\n",
  67. $charsetInfo->charset, $charsetInfo->number, $field->charsetnr);
  68. }
  69. if ($field->length != $charsetInfo->max_length) {
  70. printf("[005] Expecting length %d got %d\n",
  71. $charsetInfo->max_length, $field->max_length);
  72. }
  73. var_dump(mysqli_field_tell($res));
  74. var_dump(mysqli_field_seek($res, 2));
  75. var_dump(mysqli_fetch_field($res));
  76. var_dump(mysqli_field_seek($res, PHP_INT_MAX + 1));
  77. if (!is_null($tmp = @mysqli_field_seek($res, 0, "too many")))
  78. printf("[004] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  79. mysqli_free_result($res);
  80. if (!$res = mysqli_query($link, "SELECT NULL as _null", MYSQLI_STORE_RESULT)) {
  81. printf("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  82. }
  83. var_dump(mysqli_field_seek($res, 0));
  84. var_dump(mysqli_fetch_field($res));
  85. mysqli_free_result($res);
  86. var_dump(mysqli_field_seek($res, 0));
  87. mysqli_close($link);
  88. print "done!";
  89. ?>
  90. --CLEAN--
  91. <?php
  92. require_once("clean_table.inc");
  93. ?>
  94. --EXPECTF--
  95. Warning: mysqli_field_seek(): Invalid field offset in %s on line %d
  96. bool(false)
  97. object(stdClass)#%d (13) {
  98. [%u|b%"name"]=>
  99. %unicode|string%(2) "id"
  100. [%u|b%"orgname"]=>
  101. %unicode|string%(2) "id"
  102. [%u|b%"table"]=>
  103. %unicode|string%(4) "test"
  104. [%u|b%"orgtable"]=>
  105. %unicode|string%(4) "test"
  106. [%u|b%"def"]=>
  107. %unicode|string%(0) ""
  108. [%u|b%"db"]=>
  109. %unicode|string%(%d) "%s"
  110. [%u|b%"catalog"]=>
  111. %unicode|string%(%d) "%s"
  112. [%u|b%"max_length"]=>
  113. int(0)
  114. [%u|b%"length"]=>
  115. int(11)
  116. [%u|b%"charsetnr"]=>
  117. int(63)
  118. [%u|b%"flags"]=>
  119. int(49155)
  120. [%u|b%"type"]=>
  121. int(3)
  122. [%u|b%"decimals"]=>
  123. int(0)
  124. }
  125. bool(true)
  126. object(stdClass)#%d (13) {
  127. [%u|b%"name"]=>
  128. %unicode|string%(2) "id"
  129. [%u|b%"orgname"]=>
  130. %unicode|string%(2) "id"
  131. [%u|b%"table"]=>
  132. %unicode|string%(4) "test"
  133. [%u|b%"orgtable"]=>
  134. %unicode|string%(4) "test"
  135. [%u|b%"def"]=>
  136. %unicode|string%(0) ""
  137. [%u|b%"db"]=>
  138. %unicode|string%(%d) "%s"
  139. [%u|b%"catalog"]=>
  140. %unicode|string%(%d) "%s"
  141. [%u|b%"max_length"]=>
  142. int(0)
  143. [%u|b%"length"]=>
  144. int(11)
  145. [%u|b%"charsetnr"]=>
  146. int(63)
  147. [%u|b%"flags"]=>
  148. int(49155)
  149. [%u|b%"type"]=>
  150. int(3)
  151. [%u|b%"decimals"]=>
  152. int(0)
  153. }
  154. bool(true)
  155. object(stdClass)#%d (13) {
  156. [%u|b%"name"]=>
  157. %unicode|string%(5) "label"
  158. [%u|b%"orgname"]=>
  159. %unicode|string%(5) "label"
  160. [%u|b%"table"]=>
  161. %unicode|string%(4) "test"
  162. [%u|b%"orgtable"]=>
  163. %unicode|string%(4) "test"
  164. [%u|b%"def"]=>
  165. %unicode|string%(0) ""
  166. [%u|b%"db"]=>
  167. %unicode|string%(%d) "%s"
  168. [%u|b%"catalog"]=>
  169. %unicode|string%(%d) "%s"
  170. [%u|b%"max_length"]=>
  171. int(%d)
  172. [%u|b%"length"]=>
  173. int(%d)
  174. [%u|b%"charsetnr"]=>
  175. int(%d)
  176. [%u|b%"flags"]=>
  177. int(0)
  178. [%u|b%"type"]=>
  179. int(254)
  180. [%u|b%"decimals"]=>
  181. int(0)
  182. }
  183. int(2)
  184. Warning: mysqli_field_seek(): Invalid field offset in %s on line %d
  185. bool(false)
  186. bool(false)
  187. Warning: mysqli_field_seek(): Invalid field offset in %s on line %d
  188. bool(false)
  189. bool(true)
  190. object(stdClass)#%d (13) {
  191. [%u|b%"name"]=>
  192. %unicode|string%(5) "_null"
  193. [%u|b%"orgname"]=>
  194. %unicode|string%(0) ""
  195. [%u|b%"table"]=>
  196. %unicode|string%(0) ""
  197. [%u|b%"orgtable"]=>
  198. %unicode|string%(0) ""
  199. [%u|b%"def"]=>
  200. %unicode|string%(0) ""
  201. [%u|b%"db"]=>
  202. %unicode|string%(0) ""
  203. [%u|b%"catalog"]=>
  204. %unicode|string%(%d) "%s"
  205. [%u|b%"max_length"]=>
  206. int(0)
  207. [%u|b%"length"]=>
  208. int(0)
  209. [%u|b%"charsetnr"]=>
  210. int(63)
  211. [%u|b%"flags"]=>
  212. int(32896)
  213. [%u|b%"type"]=>
  214. int(6)
  215. [%u|b%"decimals"]=>
  216. int(0)
  217. }
  218. Warning: mysqli_field_seek(): Couldn't fetch mysqli_result in %s on line %d
  219. NULL
  220. done!