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