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