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