mysqli_multi_query.phpt 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. --TEST--
  2. mysqli_multi_query()
  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. $tmp = NULL;
  13. $link = NULL;
  14. if (!is_null($tmp = @mysqli_multi_query()))
  15. printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  16. if (!is_null($tmp = @mysqli_multi_query($link)))
  17. printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  18. require('table.inc');
  19. if (false !== ($tmp = mysqli_multi_query($link, "")))
  20. printf("[003] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
  21. 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"))
  22. printf("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  23. $i = 0;
  24. do {
  25. $res = mysqli_store_result($link);
  26. while ($row = mysqli_fetch_array($res))
  27. ;
  28. mysqli_free_result($res);
  29. $i++;
  30. } while (mysqli_next_result($link));
  31. printf("[006] %d\n", $i);
  32. if (!mysqli_multi_query($link, "ALTER TABLE test MODIFY id INT AUTO_INCREMENT; INSERT INTO test(label) VALUES ('a'); SELECT id, label FROM test ORDER BY id"))
  33. printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  34. $i = 0;
  35. while (mysqli_next_result($link) && ($res = mysqli_store_result($link))) {
  36. while ($row = mysqli_fetch_array($res))
  37. ;
  38. mysqli_free_result($res);
  39. printf("%d/%d\n", $i, mysqli_insert_id($link));
  40. $i++;
  41. }
  42. printf("[008] %d\n", $i);
  43. if (!mysqli_multi_query($link, "SELECT id, label FROM test"))
  44. printf("[009] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  45. $i = 0;
  46. while (mysqli_next_result($link) && ($res = mysqli_store_result($link))) {
  47. while ($row = mysqli_fetch_array($res))
  48. $i++;
  49. mysqli_free_result($res);
  50. }
  51. printf("[010] %d\n", $i);
  52. if (!mysqli_multi_query($link, "SELECT 1 AS num, 'a' AS somechar; SELECT 2 AS num, 'a' AS somechar; SELECT 3 AS num, 'a' AS somechar"))
  53. printf("[011] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  54. $res_num = 1;
  55. do {
  56. if (!$res = mysqli_store_result($link)) {
  57. printf("[012 - %d] [%d] %s\n", $res_num, mysqli_errno($link), mysqli_error($link));
  58. continue;
  59. }
  60. $num_rows = 0;
  61. while ($row = mysqli_fetch_array($res)) {
  62. $num_rows++;
  63. if ($row['num'] != $res_num)
  64. printf("[013 - %d] Expecting %s got %s\n", $res_num, $res_num, $row['num']);
  65. if ($row['somechar'] != "a")
  66. printf("[014 - %d] Expecting a got %s\n", $res_num, $row['somechar']);
  67. if (1 == $num_rows) {
  68. /* simple metadata check */
  69. if (!($lengths = mysqli_fetch_lengths($res)))
  70. printf("[015 - %d] [%d] %s\n", $res_num, mysqli_errno($link), mysqli_error($link));
  71. if (count($lengths) != 2)
  72. printf("[016 - %d] Expecting 2 column lengths got %d [%d] %s\n", $res_num, count($lengths));
  73. foreach ($lengths as $k => $length)
  74. if ($length <= 0)
  75. printf("[017 - %d] Strange column lengths for column %d, got %d expecting any > 0\n",
  76. $res_num, $k, $length);
  77. }
  78. }
  79. if ($num_rows != 1)
  80. printf("[018 - %d] Expecting 1 row, got %d rows\n", $num_rows);
  81. $res_num++;
  82. mysqli_free_result($res);
  83. } while (@mysqli_next_result($link));
  84. if ($res_num != 4)
  85. printf("[015] Expecting 3 result sets got %d result set[s]\n", $res_num);
  86. mysqli_close($link);
  87. var_dump(mysqli_multi_query($link, "SELECT id, label FROM test"));
  88. print "done!";
  89. ?>
  90. --CLEAN--
  91. <?php
  92. require_once("clean_table.inc");
  93. ?>
  94. --EXPECTF--
  95. Strict Standards: mysqli_next_result(): There is no next result set. Please, call mysqli_more_results()/mysqli::more_results() to check whether to call this function/method in %s on line %d
  96. [006] 3
  97. [008] 0
  98. [009] [2014] Commands out of sync; you can't run this command now
  99. Strict Standards: mysqli_next_result(): There is no next result set. Please, call mysqli_more_results()/mysqli::more_results() to check whether to call this function/method in %s on line %d
  100. [010] 7
  101. Warning: mysqli_multi_query(): Couldn't fetch mysqli in %s on line %d
  102. bool(false)
  103. done!