1--TEST-- 2MySQL PDOStatement->nextRowSet() with PDO::MYSQL_ATTR_MULTI_STATEMENTS either true or false 3--EXTENSIONS-- 4pdo_mysql 5--SKIPIF-- 6<?php 7require_once __DIR__ . '/inc/mysql_pdo_test.inc'; 8MySQLPDOTest::skip(); 9?> 10--FILE-- 11<?php 12 require_once __DIR__ . '/inc/mysql_pdo_test.inc'; 13 $db = MySQLPDOTest::factory(); 14 $db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); 15 16 $table = 'pdo_mysql_multi_stmt_nextrowset'; 17 $procedure = 'pdo_mysql_multi_stmt_nextrowset_p'; 18 MySQLPDOTest::createTestTable($table, $db); 19 20 function test_proc($db) { 21 global $table; 22 global $procedure; 23 24 $db->exec("DROP PROCEDURE IF EXISTS {$procedure}"); 25 $db->exec("CREATE PROCEDURE {$procedure}() BEGIN SELECT id FROM $table ORDER BY id ASC LIMIT 3; SELECT id, label FROM {$table} WHERE id < 4 ORDER BY id DESC LIMIT 3; END;"); 26 $stmt = $db->query("CALL {$procedure}()"); 27 do { 28 var_dump($stmt->fetchAll(PDO::FETCH_ASSOC)); 29 } while ($stmt->nextRowSet()); 30 var_dump($stmt->nextRowSet()); 31 } 32 33 try { 34 // Using native PS for proc, since emulated fails. 35 printf("Native PS...\n"); 36 foreach (array(false, true) as $multi) { 37 $value = $multi ? 'true' : 'false'; 38 echo "\nTesting with PDO::MYSQL_ATTR_MULTI_STATEMENTS set to {$value}\n"; 39 $dsn = MySQLPDOTest::getDSN(); 40 $user = PDO_MYSQL_TEST_USER; 41 $pass = PDO_MYSQL_TEST_PASS; 42 $db = new PDO($dsn, $user, $pass, array(PDO::MYSQL_ATTR_MULTI_STATEMENTS => $multi)); 43 $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); 44 $db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); 45 $db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, 1); 46 $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0); 47 test_proc($db); 48 49 $db = new PDO($dsn, $user, $pass, array(PDO::MYSQL_ATTR_MULTI_STATEMENTS => $multi)); 50 $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); 51 $db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); 52 $db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, 0); 53 $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0); 54 55 test_proc($db); 56 57 // Switch back to emulated prepares to verify multi statement attribute. 58 $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1); 59 // This will fail when $multi is false. 60 $stmt = $db->query("SELECT * FROM {$table}; INSERT INTO {$table} (id, label) VALUES (99, 'x')"); 61 if ($stmt !== false) { 62 $stmt->closeCursor(); 63 } 64 $info = $db->errorInfo(); 65 var_dump($info[0]); 66 } 67 } catch (PDOException $e) { 68 printf("[001] %s [%s] %s\n", 69 $e->getMessage(), $db->errorCode(), implode(' ', $db->errorInfo())); 70 } 71 72 print "done!"; 73?> 74--CLEAN-- 75<?php 76require_once __DIR__ . '/inc/mysql_pdo_test.inc'; 77$db = MySQLPDOTest::factory(); 78$db->exec('DROP TABLE IF EXISTS pdo_mysql_multi_stmt_nextrowset'); 79$db->exec('DROP PROCEDURE IF EXISTS pdo_mysql_multi_stmt_nextrowset_p'); 80?> 81--EXPECTF-- 82Native PS... 83 84Testing with PDO::MYSQL_ATTR_MULTI_STATEMENTS set to false 85array(3) { 86 [0]=> 87 array(1) { 88 ["id"]=> 89 string(1) "1" 90 } 91 [1]=> 92 array(1) { 93 ["id"]=> 94 string(1) "2" 95 } 96 [2]=> 97 array(1) { 98 ["id"]=> 99 string(1) "3" 100 } 101} 102array(3) { 103 [0]=> 104 array(2) { 105 ["id"]=> 106 string(1) "3" 107 ["label"]=> 108 string(1) "c" 109 } 110 [1]=> 111 array(2) { 112 ["id"]=> 113 string(1) "2" 114 ["label"]=> 115 string(1) "b" 116 } 117 [2]=> 118 array(2) { 119 ["id"]=> 120 string(1) "1" 121 ["label"]=> 122 string(1) "a" 123 } 124} 125array(0) { 126} 127bool(false) 128array(3) { 129 [0]=> 130 array(1) { 131 ["id"]=> 132 string(1) "1" 133 } 134 [1]=> 135 array(1) { 136 ["id"]=> 137 string(1) "2" 138 } 139 [2]=> 140 array(1) { 141 ["id"]=> 142 string(1) "3" 143 } 144} 145array(3) { 146 [0]=> 147 array(2) { 148 ["id"]=> 149 string(1) "3" 150 ["label"]=> 151 string(1) "c" 152 } 153 [1]=> 154 array(2) { 155 ["id"]=> 156 string(1) "2" 157 ["label"]=> 158 string(1) "b" 159 } 160 [2]=> 161 array(2) { 162 ["id"]=> 163 string(1) "1" 164 ["label"]=> 165 string(1) "a" 166 } 167} 168array(0) { 169} 170bool(false) 171 172Warning: PDO::query(): SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your %s server version for the right syntax to use near 'INSERT INTO pdo_mysql_multi_stmt_nextrowset (id, label) VALUES (99, 'x')' at line 1 in %s on line %d 173string(5) "42000" 174 175Testing with PDO::MYSQL_ATTR_MULTI_STATEMENTS set to true 176array(3) { 177 [0]=> 178 array(1) { 179 ["id"]=> 180 string(1) "1" 181 } 182 [1]=> 183 array(1) { 184 ["id"]=> 185 string(1) "2" 186 } 187 [2]=> 188 array(1) { 189 ["id"]=> 190 string(1) "3" 191 } 192} 193array(3) { 194 [0]=> 195 array(2) { 196 ["id"]=> 197 string(1) "3" 198 ["label"]=> 199 string(1) "c" 200 } 201 [1]=> 202 array(2) { 203 ["id"]=> 204 string(1) "2" 205 ["label"]=> 206 string(1) "b" 207 } 208 [2]=> 209 array(2) { 210 ["id"]=> 211 string(1) "1" 212 ["label"]=> 213 string(1) "a" 214 } 215} 216array(0) { 217} 218bool(false) 219array(3) { 220 [0]=> 221 array(1) { 222 ["id"]=> 223 string(1) "1" 224 } 225 [1]=> 226 array(1) { 227 ["id"]=> 228 string(1) "2" 229 } 230 [2]=> 231 array(1) { 232 ["id"]=> 233 string(1) "3" 234 } 235} 236array(3) { 237 [0]=> 238 array(2) { 239 ["id"]=> 240 string(1) "3" 241 ["label"]=> 242 string(1) "c" 243 } 244 [1]=> 245 array(2) { 246 ["id"]=> 247 string(1) "2" 248 ["label"]=> 249 string(1) "b" 250 } 251 [2]=> 252 array(2) { 253 ["id"]=> 254 string(1) "1" 255 ["label"]=> 256 string(1) "a" 257 } 258} 259array(0) { 260} 261bool(false) 262string(5) "00000" 263done! 264