mysqli_stmt_get_result2.phpt 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. --TEST--
  2. mysqli_stmt_get_result()
  3. --SKIPIF--
  4. <?php
  5. require_once('skipif.inc');
  6. require_once('skipifemb.inc');
  7. require_once('skipifconnectfailure.inc');
  8. if (!function_exists('mysqli_stmt_get_result'))
  9. die('skip mysqli_stmt_get_result not available');
  10. ?>
  11. --FILE--
  12. <?php
  13. /*
  14. NOTE: no datatype tests here! This is done by
  15. mysqli_stmt_bind_result.phpt already. Restrict
  16. this test case to the basics.
  17. */
  18. require_once("connect.inc");
  19. $tmp = NULL;
  20. $link = NULL;
  21. if (!is_null($tmp = @mysqli_stmt_get_result()))
  22. printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  23. if (!is_null($tmp = @mysqli_stmt_get_result($link)))
  24. printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  25. require('table.inc');
  26. if (!$stmt = mysqli_stmt_init($link))
  27. printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  28. if (!is_null($tmp = @mysqli_stmt_get_result($stmt, "foo")))
  29. printf("[004] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  30. if (!mysqli_stmt_prepare($stmt, "SELECT id, label FROM test ORDER BY id ASC LIMIT 1"))
  31. printf("[005] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  32. if (!mysqli_stmt_execute($stmt))
  33. printf("[006] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  34. if (!is_object($res = mysqli_stmt_get_result($stmt)) || 'mysqli_result' != get_class($res)) {
  35. printf("[007] Expecting object/mysqli_result got %s/%s, [%d] %s\n",
  36. gettype($res), $res, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  37. }
  38. while ($row = mysqli_fetch_assoc($res))
  39. var_dump($row);
  40. var_dump(mysqli_fetch_assoc($res));
  41. mysqli_free_result($res);
  42. if (false !== ($res = mysqli_stmt_get_result($stmt))) {
  43. printf("[008] boolean/false got %s/%s, [%d] %s\n",
  44. gettype($res), $res, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  45. }
  46. mysqli_stmt_execute($stmt);
  47. if (!is_object($res = mysqli_stmt_get_result($stmt)) || 'mysqli_result' != get_class($res)) {
  48. printf("[009] Expecting object/mysqli_result got %s/%s, [%d] %s\n",
  49. gettype($res), $res, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  50. }
  51. while ($row = mysqli_fetch_assoc($res))
  52. var_dump($row);
  53. var_dump(mysqli_fetch_assoc($res));
  54. mysqli_free_result($res);
  55. mysqli_stmt_close($stmt);
  56. if (!($stmt = mysqli_stmt_init($link)) ||
  57. !mysqli_stmt_prepare($stmt, "SELECT id, label FROM test ORDER BY id ASC LIMIT 2") ||
  58. !mysqli_stmt_execute($stmt))
  59. printf("[010] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  60. $id = $label = null;
  61. if (!mysqli_stmt_bind_result($stmt, $id, $label))
  62. printf("[011] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  63. if (!mysqli_stmt_fetch($stmt))
  64. printf("[012] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  65. if (false !== ($res = mysqli_stmt_get_result($stmt))) {
  66. printf("[013] boolean/false got %s/%s, [%d] %s\n",
  67. gettype($res), $res, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  68. }
  69. mysqli_stmt_close($stmt);
  70. if (!($stmt = mysqli_stmt_init($link)) ||
  71. !mysqli_stmt_prepare($stmt, "SELECT id, label FROM test ORDER BY id ASC LIMIT 2") ||
  72. !mysqli_stmt_execute($stmt))
  73. printf("[014] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  74. if (!is_object($res = mysqli_stmt_get_result($stmt)) || 'mysqli_result' != get_class($res)) {
  75. printf("[015] Expecting object/mysqli_result got %s/%s, [%d] %s\n",
  76. gettype($res), $res, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  77. }
  78. $id = $label = null;
  79. if (!mysqli_stmt_bind_result($stmt, $id, $label))
  80. printf("[016] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  81. if (!mysqli_stmt_fetch($stmt))
  82. printf("[017] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  83. mysqli_stmt_close($stmt);
  84. if (!($stmt = mysqli_stmt_init($link)) ||
  85. !mysqli_stmt_prepare($stmt, "SELECT id, label FROM test ORDER BY id ASC LIMIT 2") ||
  86. !mysqli_stmt_execute($stmt))
  87. printf("[018] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  88. if (!is_object($res = mysqli_stmt_get_result($stmt)) || 'mysqli_result' != get_class($res)) {
  89. printf("[019] Expecting object/mysqli_result got %s/%s, [%d] %s\n",
  90. gettype($res), $res, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  91. }
  92. $id = $label = null;
  93. if (!mysqli_stmt_bind_result($stmt, $id, $label))
  94. printf("[020] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  95. $row = mysqli_fetch_assoc($res);
  96. if (NULL !== $id || NULL !== $label)
  97. printf("[021] Bound variables should not have been set\n");
  98. mysqli_free_result($res);
  99. mysqli_stmt_close($stmt);
  100. if (!($stmt = mysqli_stmt_init($link)) ||
  101. !mysqli_stmt_prepare($stmt, "SELECT id, label FROM test ORDER BY id ASC LIMIT 2") ||
  102. !mysqli_stmt_execute($stmt))
  103. printf("[022] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  104. if (!is_object($res = mysqli_stmt_get_result($stmt)) || 'mysqli_result' != get_class($res)) {
  105. printf("[023] Expecting object/mysqli_result got %s/%s, [%d] %s\n",
  106. gettype($res), $res, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  107. }
  108. if (!in_array($res->type, array(MYSQLI_STORE_RESULT, MYSQLI_USE_RESULT))) {
  109. printf("[024] Unknown result set type %s\n", $res->type);
  110. }
  111. if ($res->type !== MYSQLI_STORE_RESULT)
  112. printf("[025] Expecting int/%d got %s/%s", MYSQLI_STORE_RESULT, gettype($res->type), $res->type);
  113. mysqli_free_result($res);
  114. mysqli_stmt_close($stmt);
  115. mysqli_close($link);
  116. if (NULL !== ($res = mysqli_stmt_get_result($stmt))) {
  117. printf("[022] Expecting NULL got %s/%s\n",
  118. gettype($res), $res);
  119. }
  120. print "done!";
  121. ?>
  122. --CLEAN--
  123. <?php
  124. require_once("clean_table.inc");
  125. ?>
  126. --EXPECTF--
  127. array(2) {
  128. [%u|b%"id"]=>
  129. int(1)
  130. [%u|b%"label"]=>
  131. %unicode|string%(1) "a"
  132. }
  133. NULL
  134. array(2) {
  135. [%u|b%"id"]=>
  136. int(1)
  137. [%u|b%"label"]=>
  138. %unicode|string%(1) "a"
  139. }
  140. NULL
  141. [017] [2014] Commands out of sync; you can't run this command now
  142. Warning: mysqli_stmt_get_result(): Couldn't fetch mysqli_stmt in %s on line %d
  143. done!