1--TEST-- 2MySQL PDOStatement->nextRowSet() 3--EXTENSIONS-- 4pdo_mysql 5--SKIPIF-- 6<?php 7require_once __DIR__ . '/inc/mysql_pdo_test.inc'; 8MySQLPDOTest::skip(); 9MySQLPDOTest::skipNotMySQLnd(); 10?> 11--FILE-- 12<?php 13 require_once __DIR__ . '/inc/mysql_pdo_test.inc'; 14 $db = MySQLPDOTest::factory(); 15 $db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); 16 17 $table = 'pdo_mysql_stmt_nextrowset'; 18 $procedure = 'pdo_mysql_stmt_nextrowset_p'; 19 20 MySQLPDOTest::createTestTable($table, $db); 21 22 $stmt = $db->query("SELECT id FROM {$table}"); 23 if (false !== ($tmp = $stmt->nextRowSet())) 24 printf("[002] Expecting false got %s\n", var_export($tmp, true)); 25 26 function test_proc1($db) { 27 global $procedure; 28 29 $stmt = $db->query('SELECT @VERSION as _version'); 30 $tmp = $stmt->fetch(PDO::FETCH_ASSOC); 31 assert($tmp['_version'] === NULL); 32 while ($stmt->fetch()) ; 33 34 $db->exec("DROP PROCEDURE IF EXISTS {$procedure}"); 35 $db->exec("CREATE PROCEDURE {$procedure}(OUT ver_param VARCHAR(25)) BEGIN SELECT VERSION() INTO ver_param; END;"); 36 $db->exec("CALL {$procedure}(@VERSION)"); 37 $stmt = $db->query('SELECT @VERSION as _version'); 38 var_dump($stmt->fetchAll(PDO::FETCH_ASSOC)); 39 var_dump($stmt->nextRowSet()); 40 } 41 42 function test_proc2($db) { 43 global $table; 44 global $procedure; 45 46 $db->exec("DROP PROCEDURE IF EXISTS {$procedure}"); 47 $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;"); 48 $stmt = $db->query("CALL {$procedure}()"); 49 do { 50 var_dump($stmt->fetchAll(PDO::FETCH_ASSOC)); 51 } while ($stmt->nextRowSet()); 52 var_dump($stmt->nextRowSet()); 53 54 echo "Skip fetchAll(): "; 55 unset($stmt); 56 $stmt = $db->query("CALL {$procedure}()"); 57 var_dump($stmt->nextRowSet()); 58 $stmt->closeCursor(); 59 } 60 61 try { 62 // Emulated PS 63 printf("Emulated PS...\n"); 64 $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1); 65 66 $db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, 1); 67 test_proc1($db); 68 test_proc2($db); 69 70 $db = MySQLPDOTest::factory(); 71 $db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); 72 $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1); 73 $db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, 0); 74 test_proc1($db); 75 test_proc2($db); 76 77 // Native PS 78 printf("Native PS...\n"); 79 $db = MySQLPDOTest::factory(); 80 $db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); 81 $db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, 1); 82 $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0); 83 test_proc1($db); 84 test_proc2($db); 85 86 $db = MySQLPDOTest::factory(); 87 $db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); 88 $db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, 0); 89 $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0); 90 91 test_proc1($db); 92 test_proc2($db); 93 } catch (PDOException $e) { 94 printf("[001] %s [%s] %s\n", 95 $e->getMessage(), $db->errorCode(), implode(' ', $db->errorInfo())); 96 } 97 98 print "done!"; 99?> 100--CLEAN-- 101<?php 102require_once __DIR__ . '/inc/mysql_pdo_test.inc'; 103$db = MySQLPDOTest::factory(); 104$db->exec('DROP TABLE IF EXISTS pdo_mysql_stmt_nextrowset'); 105$db->exec('DROP PROCEDURE IF EXISTS pdo_mysql_stmt_nextrowset_p'); 106?> 107--EXPECTF-- 108Emulated PS... 109array(1) { 110 [0]=> 111 array(1) { 112 ["_version"]=> 113 string(%d) "%s" 114 } 115} 116bool(false) 117array(3) { 118 [0]=> 119 array(1) { 120 ["id"]=> 121 string(1) "1" 122 } 123 [1]=> 124 array(1) { 125 ["id"]=> 126 string(1) "2" 127 } 128 [2]=> 129 array(1) { 130 ["id"]=> 131 string(1) "3" 132 } 133} 134array(3) { 135 [0]=> 136 array(2) { 137 ["id"]=> 138 string(1) "3" 139 ["label"]=> 140 string(1) "c" 141 } 142 [1]=> 143 array(2) { 144 ["id"]=> 145 string(1) "2" 146 ["label"]=> 147 string(1) "b" 148 } 149 [2]=> 150 array(2) { 151 ["id"]=> 152 string(1) "1" 153 ["label"]=> 154 string(1) "a" 155 } 156} 157array(0) { 158} 159bool(false) 160Skip fetchAll(): bool(true) 161array(1) { 162 [0]=> 163 array(1) { 164 ["_version"]=> 165 string(%d) "%s" 166 } 167} 168bool(false) 169array(3) { 170 [0]=> 171 array(1) { 172 ["id"]=> 173 string(1) "1" 174 } 175 [1]=> 176 array(1) { 177 ["id"]=> 178 string(1) "2" 179 } 180 [2]=> 181 array(1) { 182 ["id"]=> 183 string(1) "3" 184 } 185} 186array(3) { 187 [0]=> 188 array(2) { 189 ["id"]=> 190 string(1) "3" 191 ["label"]=> 192 string(1) "c" 193 } 194 [1]=> 195 array(2) { 196 ["id"]=> 197 string(1) "2" 198 ["label"]=> 199 string(1) "b" 200 } 201 [2]=> 202 array(2) { 203 ["id"]=> 204 string(1) "1" 205 ["label"]=> 206 string(1) "a" 207 } 208} 209array(0) { 210} 211bool(false) 212Skip fetchAll(): bool(true) 213Native PS... 214array(1) { 215 [0]=> 216 array(1) { 217 ["_version"]=> 218 string(%d) "%s" 219 } 220} 221bool(false) 222array(3) { 223 [0]=> 224 array(1) { 225 ["id"]=> 226 string(1) "1" 227 } 228 [1]=> 229 array(1) { 230 ["id"]=> 231 string(1) "2" 232 } 233 [2]=> 234 array(1) { 235 ["id"]=> 236 string(1) "3" 237 } 238} 239array(3) { 240 [0]=> 241 array(2) { 242 ["id"]=> 243 string(1) "3" 244 ["label"]=> 245 string(1) "c" 246 } 247 [1]=> 248 array(2) { 249 ["id"]=> 250 string(1) "2" 251 ["label"]=> 252 string(1) "b" 253 } 254 [2]=> 255 array(2) { 256 ["id"]=> 257 string(1) "1" 258 ["label"]=> 259 string(1) "a" 260 } 261} 262array(0) { 263} 264bool(false) 265Skip fetchAll(): bool(true) 266array(1) { 267 [0]=> 268 array(1) { 269 ["_version"]=> 270 string(%d) "%s" 271 } 272} 273bool(false) 274array(3) { 275 [0]=> 276 array(1) { 277 ["id"]=> 278 string(1) "1" 279 } 280 [1]=> 281 array(1) { 282 ["id"]=> 283 string(1) "2" 284 } 285 [2]=> 286 array(1) { 287 ["id"]=> 288 string(1) "3" 289 } 290} 291array(3) { 292 [0]=> 293 array(2) { 294 ["id"]=> 295 string(1) "3" 296 ["label"]=> 297 string(1) "c" 298 } 299 [1]=> 300 array(2) { 301 ["id"]=> 302 string(1) "2" 303 ["label"]=> 304 string(1) "b" 305 } 306 [2]=> 307 array(2) { 308 ["id"]=> 309 string(1) "1" 310 ["label"]=> 311 string(1) "a" 312 } 313} 314array(0) { 315} 316bool(false) 317Skip fetchAll(): bool(true) 318done! 319