mysqli_stmt_get_result.phpt 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. // stmt object status test
  29. if (NULL !== ($tmp = mysqli_stmt_fetch($stmt)))
  30. printf("[004] Expecting NULL, got %s/%s\n", gettype($tmp), var_export($tmp, 1));
  31. if (!mysqli_stmt_prepare($stmt, "SELECT id, label FROM test ORDER BY id LIMIT 2"))
  32. printf("[005] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  33. // FIXME - different versions return different values ?!
  34. if ((NULL !== ($tmp = mysqli_stmt_get_result($stmt))) && (false !== $tmp))
  35. printf("[006] Expecting NULL or boolean/false, got %s/%s\n", gettype($tmp), var_export($tmp, 1));
  36. if (!mysqli_stmt_execute($stmt))
  37. printf("[007] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  38. if (!mysqli_stmt_store_result($stmt))
  39. printf("[008] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  40. if (is_object($tmp = mysqli_stmt_store_result($stmt)))
  41. printf("[009] non-object, got %s/%s\n", gettype($tmp), var_export($tmp, 1));
  42. mysqli_stmt_close($stmt);
  43. if (!$stmt = mysqli_stmt_init($link))
  44. printf("[010] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  45. // stmt object status test
  46. if (NULL !== ($tmp = mysqli_stmt_fetch($stmt)))
  47. printf("[011] Expecting NULL, got %s/%s\n", gettype($tmp), var_export($tmp, 1));
  48. if (!mysqli_stmt_prepare($stmt, "SELECT id, label FROM test ORDER BY id LIMIT 2"))
  49. printf("[012] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  50. // FIXME - different versions return different values ?!
  51. if ((NULL !== ($tmp = mysqli_stmt_get_result($stmt))) && (false !== $tmp))
  52. printf("[013] Expecting NULL or boolean/false, got %s/%s\n", gettype($tmp), var_export($tmp, 1));
  53. if (!mysqli_stmt_execute($stmt))
  54. printf("[014] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  55. if (!is_object($tmp = mysqli_stmt_get_result($stmt)))
  56. printf("[016] NULL, got %s/%s\n", gettype($tmp), var_export($tmp, 1));
  57. mysqli_free_result($tmp);
  58. mysqli_stmt_close($stmt);
  59. if (!$stmt = mysqli_stmt_init($link))
  60. printf("[017] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  61. // stmt object status test
  62. if (NULL !== ($tmp = mysqli_stmt_get_result($stmt)))
  63. printf("[018] Expecting NULL, got %s/%s\n", gettype($tmp), var_export($tmp, 1));
  64. if (!mysqli_stmt_prepare($stmt, "SELECT id, label FROM test ORDER BY id LIMIT 2"))
  65. printf("[019] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  66. if (false !== ($tmp = mysqli_stmt_get_result($stmt)))
  67. printf("[020] Expecting false, got %s/%s\n", gettype($tmp), var_export($tmp, 1));
  68. if (!mysqli_stmt_execute($stmt))
  69. printf("[023] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  70. if (!is_object($tmp = mysqli_stmt_get_result($stmt)))
  71. printf("[024] Expecting object, got %s/%s\n", gettype($tmp), var_export($tmp, 1));
  72. if (false !== ($tmp = mysqli_stmt_fetch($stmt)))
  73. printf("[025] false, got %s/%s\n", gettype($tmp), var_export($tmp, 1));
  74. if (true !== ($tmp = mysqli_stmt_bind_result($stmt, $id, $label))) {
  75. printf("[026] [%d] [%s]\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  76. printf("[027] [%d] [%s]\n", mysqli_errno($link), mysqli_error($link));
  77. printf("[028] Expecting boolean/true, got %s/%s\n", gettype($tmp), var_export($tmp, 1));
  78. }
  79. if (false !== ($tmp = mysqli_stmt_fetch($stmt)))
  80. printf("[029] false, got %s/%s\n", gettype($tmp), var_export($tmp, 1));
  81. mysqli_stmt_close($stmt);
  82. if (!$stmt = mysqli_stmt_init($link))
  83. printf("[032] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  84. if (!mysqli_stmt_prepare($stmt, "SELECT id, label FROM test ORDER BY id LIMIT 2"))
  85. printf("[033] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  86. if (!mysqli_stmt_execute($stmt))
  87. printf("[034] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  88. $id = NULL;
  89. $label = NULL;
  90. if (true !== ($tmp = mysqli_stmt_bind_result($stmt, $id, $label)))
  91. printf("[035] Expecting boolean/true, got %s/%s\n", gettype($tmp), var_export($tmp, 1));
  92. if (!is_object($tmp = $result = mysqli_stmt_get_result($stmt)))
  93. printf("[036] Expecting array, got %s/%s, [%d] %s\n",
  94. gettype($tmp), var_export($tmp, 1),
  95. mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  96. if (false !== ($tmp = mysqli_stmt_fetch($stmt)))
  97. printf("[037] Expecting boolean/false, got %s/%s, [%d] %s\n",
  98. gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  99. printf("[038] [%d] [%s]\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  100. printf("[039] [%d] [%s]\n", mysqli_errno($link), mysqli_error($link));
  101. while ($row = mysqli_fetch_assoc($result)) {
  102. var_dump($row);
  103. }
  104. mysqli_free_result($result);
  105. if (!mysqli_kill($link, mysqli_thread_id($link)))
  106. printf("[040] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  107. if (false !== ($tmp = mysqli_stmt_get_result($stmt)))
  108. printf("[041] Expecting false, got %s/%s\n", gettype($tmp), var_export($tmp, 1));
  109. mysqli_stmt_close($stmt);
  110. if (NULL !== ($tmp = mysqli_stmt_fetch($stmt)))
  111. printf("[042] Expecting NULL, got %s/%s\n", gettype($tmp), var_export($tmp, 1));
  112. mysqli_close($link);
  113. print "done!";
  114. ?>
  115. --CLEAN--
  116. <?php
  117. require_once("clean_table.inc");
  118. ?>
  119. --EXPECTF--
  120. Warning: mysqli_stmt_fetch(): invalid object or resource mysqli_stmt
  121. in %s on line %d
  122. Warning: mysqli_stmt_fetch(): invalid object or resource mysqli_stmt
  123. in %s on line %d
  124. Warning: mysqli_stmt_get_result(): invalid object or resource mysqli_stmt
  125. in %s on line %d
  126. [038] [2014] [Commands out of sync; you can't run this command now]
  127. [039] [0] []
  128. array(2) {
  129. [%u|b%"id"]=>
  130. int(1)
  131. [%u|b%"label"]=>
  132. %s(1) "a"
  133. }
  134. array(2) {
  135. [%u|b%"id"]=>
  136. int(2)
  137. [%u|b%"label"]=>
  138. %s(1) "b"
  139. }
  140. Warning: mysqli_stmt_fetch(): Couldn't fetch mysqli_stmt in %s on line %d
  141. done!