mysqli_next_result.phpt 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. --TEST--
  2. mysqli_next_result()
  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_next_result()))
  20. printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  21. if (!is_null($tmp = @mysqli_next_result($link)))
  22. printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  23. require('table.inc');
  24. if ($strict_on)
  25. ob_start();
  26. if (false !== ($tmp = mysqli_next_result($link)))
  27. printf("[003] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
  28. if ($strict_on) {
  29. $tmp = ob_get_contents();
  30. ob_end_clean();
  31. if (!preg_match('@Strict Standards: mysqli_next_result\(\): There is no next result set@ismU', $tmp)) {
  32. printf("[003a] Strict Standards warning missing\n");
  33. } else {
  34. $tmp = trim(preg_replace('@Strict Standards: mysqli_next_result\(\).*on line \d+@ism', '', $tmp));
  35. }
  36. print trim($tmp) . "\n";
  37. ob_start();
  38. }
  39. $res = mysqli_query($link, "SELECT 1 AS res");
  40. if (false !== ($tmp = mysqli_next_result($link)))
  41. printf("[004] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
  42. if ($strict_on) {
  43. $tmp = ob_get_contents();
  44. ob_end_clean();
  45. if (!preg_match('@Strict Standards: mysqli_next_result\(\): There is no next result set@ismU', $tmp)) {
  46. printf("[004a] Strict Standards warning missing\n");
  47. } else {
  48. $tmp = trim(preg_replace('@Strict Standards: mysqli_next_result\(\).*on line \d+@ism', '', $tmp));
  49. }
  50. print trim($tmp) . "\n";
  51. }
  52. mysqli_free_result($res);
  53. function func_test_mysqli_next_result($link, $query, $offset, $num_results, $strict_on) {
  54. if (!mysqli_multi_query($link, $query))
  55. printf("[%03d] [%d] %s\n", $offset, mysqli_errno($link), mysqli_error($link));
  56. $i = 0;
  57. if ($strict_on)
  58. ob_start();
  59. do {
  60. if ($res = mysqli_store_result($link)) {
  61. mysqli_free_result($res);
  62. $i++;
  63. }
  64. } while (true === mysqli_next_result($link));
  65. if ($strict_on) {
  66. $tmp = ob_get_contents();
  67. ob_end_clean();
  68. if (!preg_match('@Strict Standards: mysqli_next_result\(\): There is no next result set@ismU', $tmp)) {
  69. printf("[%03d] Strict Standards warning missing\n", $offset + 1);
  70. } else {
  71. $tmp = trim(preg_replace('@Strict Standards: mysqli_next_result\(\).*on line \d+@ism', '', $tmp));
  72. }
  73. print trim($tmp) . "\n";
  74. }
  75. if ($i !== $num_results) {
  76. printf("[%03d] Expecting %d result(s), got %d result(s)\n", $offset + 2, $num_results, $i);
  77. }
  78. if (mysqli_more_results($link))
  79. printf("[%03d] mysqli_more_results() indicates more results than expected\n", $offset + 3);
  80. if (!($res = mysqli_query($link, "SELECT 1 AS b"))) {
  81. printf("[%03d] [%d] %s\n", $offset + 4, mysqli_errno($link), mysqli_error($link));
  82. } else {
  83. mysqli_free_result($res);
  84. }
  85. }
  86. func_test_mysqli_next_result($link, "SELECT 1 AS a; SELECT 1 AS a, 2 AS b; SELECT id FROM test ORDER BY id LIMIT 3", 5, 3, $strict_on);
  87. func_test_mysqli_next_result($link, "SELECT 1 AS a; INSERT INTO test(id, label) VALUES (100, 'y'); SELECT 1 AS a, 2 AS b", 8, 2, $strict_on);
  88. func_test_mysqli_next_result($link, "DELETE FROM test WHERE id >= 100; SELECT 1 AS a; ", 11, 1, $strict_on);
  89. mysqli_close($link);
  90. var_dump(mysqli_next_result($link));
  91. print "done!";
  92. ?>
  93. --CLEAN--
  94. <?php
  95. require_once("clean_table.inc");
  96. ?>
  97. --EXPECTF--
  98. Warning: mysqli_next_result(): Couldn't fetch mysqli in %s on line %d
  99. NULL
  100. done!