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