1--TEST-- 2mysqli_multi_query() 3--SKIPIF-- 4<?php 5require_once('skipif.inc'); 6require_once('skipifemb.inc'); 7require_once('skipifconnectfailure.inc'); 8?> 9--FILE-- 10<?php 11 require_once("connect.inc"); 12 13 $strict_on = false; 14 if (defined('E_STRICT')) { 15 error_reporting(((int)ini_get('error_reporting')) | E_STRICT ); 16 $strict_on = true; 17 } 18 $tmp = NULL; 19 $link = NULL; 20 21 if (!is_null($tmp = @mysqli_multi_query())) 22 printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); 23 24 if (!is_null($tmp = @mysqli_multi_query($link))) 25 printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); 26 27 require('table.inc'); 28 29 if (false !== ($tmp = mysqli_multi_query($link, ""))) 30 printf("[003] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); 31 32 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")) 33 printf("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 34 35 if ($strict_on) 36 ob_start(); 37 38 $i = 0; 39 do { 40 $res = mysqli_store_result($link); 41 while ($row = mysqli_fetch_array($res)) 42 ; 43 mysqli_free_result($res); 44 $i++; 45 } while (mysqli_next_result($link)); 46 47 if ($strict_on) { 48 $tmp = ob_get_contents(); 49 ob_end_clean(); 50 if (!preg_match('@Strict Standards: mysqli_next_result\(\): There is no next result set@ismU', $tmp)) { 51 printf("[005a] Strict Standards warning missing\n"); 52 } else { 53 $tmp = trim(preg_replace('@Strict Standards: mysqli_next_result\(\).*on line \d+@ism', '', $tmp)); 54 } 55 print trim($tmp) . "\n"; 56 } 57 58 printf("[006] %d\n", $i); 59 60 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")) 61 printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 62 63 $i = 0; 64 while (mysqli_next_result($link) && ($res = mysqli_store_result($link))) { 65 66 while ($row = mysqli_fetch_array($res)) 67 ; 68 mysqli_free_result($res); 69 printf("%d/%d\n", $i, mysqli_insert_id($link)); 70 $i++; 71 } 72 printf("[008] %d\n", $i); 73 74 if (!mysqli_multi_query($link, "SELECT id, label FROM test")) 75 printf("[009] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 76 77 if ($strict_on) 78 ob_start(); 79 $i = 0; 80 while (mysqli_next_result($link) && ($res = mysqli_store_result($link))) { 81 while ($row = mysqli_fetch_array($res)) 82 $i++; 83 mysqli_free_result($res); 84 } 85 if ($strict_on) { 86 $tmp = ob_get_contents(); 87 ob_end_clean(); 88 if (!preg_match('@Strict Standards: mysqli_next_result\(\): There is no next result set@ismU', $tmp)) { 89 printf("[009a] Strict Standards warning missing\n"); 90 } else { 91 $tmp = trim(preg_replace('@Strict Standards: mysqli_next_result\(\).*on line \d+@ism', '', $tmp)); 92 } 93 print trim($tmp) . "\n"; 94 } 95 printf("[010] %d\n", $i); 96 97 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")) 98 printf("[011] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 99 100 $res_num = 1; 101 do { 102 if (!$res = mysqli_store_result($link)) { 103 printf("[012 - %d] [%d] %s\n", $res_num, mysqli_errno($link), mysqli_error($link)); 104 continue; 105 } 106 107 $num_rows = 0; 108 while ($row = mysqli_fetch_array($res)) { 109 110 $num_rows++; 111 if ($row['num'] != $res_num) 112 printf("[013 - %d] Expecting %s got %s\n", $res_num, $res_num, $row['num']); 113 if ($row['somechar'] != "a") 114 printf("[014 - %d] Expecting a got %s\n", $res_num, $row['somechar']); 115 116 if (1 == $num_rows) { 117 /* simple metadata check */ 118 if (!($lengths = mysqli_fetch_lengths($res))) 119 printf("[015 - %d] [%d] %s\n", $res_num, mysqli_errno($link), mysqli_error($link)); 120 121 if (count($lengths) != 2) 122 printf("[016 - %d] Expecting 2 column lengths got %d [%d] %s\n", $res_num, count($lengths)); 123 124 foreach ($lengths as $k => $length) 125 if ($length <= 0) 126 printf("[017 - %d] Strange column lengths for column %d, got %d expecting any > 0\n", 127 $res_num, $k, $length); 128 } 129 } 130 131 if ($num_rows != 1) 132 printf("[018 - %d] Expecting 1 row, got %d rows\n", $num_rows); 133 134 $res_num++; 135 136 mysqli_free_result($res); 137 138 } while (@mysqli_next_result($link)); 139 140 if ($res_num != 4) 141 printf("[015] Expecting 3 result sets got %d result set[s]\n", $res_num); 142 143 mysqli_close($link); 144 145 var_dump(mysqli_multi_query($link, "SELECT id, label FROM test")); 146 147 print "done!"; 148?> 149--CLEAN-- 150<?php 151 require_once("clean_table.inc"); 152?> 153--EXPECTF-- 154[006] 3 155[008] 0 156[009] [2014] Commands out of sync; you can't run this command now 157 158[010] 7 159 160Warning: mysqli_multi_query(): Couldn't fetch mysqli in %s on line %d 161NULL 162done!