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