mysqli_more_results.phpt 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. --TEST--
  2. mysqli_more_results()
  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. require_once("connect.inc");
  12. $strict_on = false;
  13. if (defined('E_STRICT')) {
  14. error_reporting(((int)ini_get('error_reporting')) | E_STRICT );
  15. $strict_on = true;
  16. }
  17. $tmp = NULL;
  18. $link = NULL;
  19. if (!is_null($tmp = @mysqli_more_results()))
  20. printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  21. if (!is_null($tmp = @mysqli_more_results($link)))
  22. printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  23. require('table.inc');
  24. print "[004]\n";
  25. var_dump(mysqli_more_results($link));
  26. if (!mysqli_multi_query($link, "SELECT 1 AS a; SELECT 1 AS a, 2 AS b; SELECT id FROM test ORDER BY id LIMIT 3"))
  27. printf("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  28. print "[006]\n";
  29. $i = 1;
  30. if ($strict_on)
  31. ob_start();
  32. if (mysqli_get_server_version($link) > 41000 && !($ret = mysqli_more_results($link)))
  33. printf("[007] Expecting boolean/true, got %s/%s\n", gettype($ret), $ret);
  34. do {
  35. $res = mysqli_store_result($link);
  36. mysqli_free_result($res);
  37. if (mysqli_more_results($link))
  38. printf("%d\n", $i++);
  39. } while (mysqli_next_result($link));
  40. if ($strict_on) {
  41. $tmp = ob_get_contents();
  42. ob_end_clean();
  43. if (!preg_match('@Strict Standards: mysqli_next_result\(\): There is no next result set@ismU', $tmp)) {
  44. printf("[008] Strict Standards warning missing\n");
  45. } else {
  46. $tmp = trim(preg_replace('@Strict Standards: mysqli_next_result\(\).*on line \d+@ism', '', $tmp));
  47. }
  48. print trim($tmp) . "\n";
  49. }
  50. if (!mysqli_multi_query($link, "SELECT 1 AS a; SELECT 1 AS a, 2 AS b; SELECT id FROM test ORDER BY id LIMIT 3"))
  51. printf("[009] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  52. print "[010]\n";
  53. $i = 1;
  54. if (mysqli_get_server_version($link) > 41000 && !($ret = mysqli_more_results($link)))
  55. printf("[011] Expecting boolean/true, got %s/%s\n", gettype($ret), $ret);
  56. if ($strict_on)
  57. ob_start();
  58. do {
  59. $res = mysqli_use_result($link);
  60. // NOTE: if you use mysqli_use_result() with mysqli_more_results() or any other info function,
  61. // you must fetch all rows before you can loop to the next result set!
  62. // See also the MySQL Reference Manual: mysql_use_result()
  63. while ($row = mysqli_fetch_array($res))
  64. ;
  65. mysqli_free_result($res);
  66. if (mysqli_more_results($link))
  67. printf("%d\n", $i++);
  68. } while (mysqli_next_result($link));
  69. if ($strict_on) {
  70. $tmp = ob_get_contents();
  71. ob_end_clean();
  72. if (!preg_match('@Strict Standards: mysqli_next_result\(\): There is no next result set@ismU', $tmp)) {
  73. printf("[008] Strict Standards warning missing\n");
  74. } else {
  75. $tmp = trim(preg_replace('@Strict Standards: mysqli_next_result\(\).*on line \d+@ism', '', $tmp));
  76. }
  77. print trim($tmp) . "\n";
  78. }
  79. mysqli_close($link);
  80. var_dump(mysqli_more_results($link));
  81. print "done!";
  82. ?>
  83. --CLEAN--
  84. <?php
  85. require_once("clean_table.inc");
  86. ?>
  87. --EXPECTF--
  88. [004]
  89. bool(false)
  90. [006]
  91. 1
  92. 2
  93. [010]
  94. 1
  95. 2
  96. Warning: mysqli_more_results(): Couldn't fetch mysqli in %s on line %d
  97. NULL
  98. done!