xref: /php-src/ext/pdo_mysql/tests/bug_61207.phpt (revision 4bb75d56)
1--TEST--
2PDO MySQL Bug #61207 (PDO::nextRowset() after a multi-statement query doesn't always work)
3--EXTENSIONS--
4pdo_mysql
5--SKIPIF--
6<?php
7require_once __DIR__ . '/inc/mysql_pdo_test.inc';
8MySQLPDOTest::skip();
9?>
10--FILE--
11<?php
12require_once __DIR__ . '/inc/mysql_pdo_test.inc';
13/** @var PDO $db */
14$db = MySQLPDOTest::factory();
15
16$db->query('CREATE TABLE `test_61207`(`id` INT)');
17
18$handle1 = $db->prepare('INSERT INTO test_61207(id) VALUES (1);
19                          SELECT * FROM test_61207 WHERE id = ?;
20                          UPDATE test_61207 SET id = 2 WHERE id = ?;');
21
22$handle1->bindValue(1, '1');
23$handle1->bindValue(2, '1');
24
25$handle1->execute();
26$i = 1;
27print("Handle 1:\n");
28do {
29    print('Rowset ' . $i++ . "\n");
30    if ($handle1->columnCount() > 0)
31        print("Results detected\n");
32} while($handle1->nextRowset());
33
34$handle2 = $db->prepare('SELECT * FROM test_61207 WHERE id = ?;
35                           UPDATE test_61207 SET id = 1 WHERE id = ?;');
36
37$handle2->bindValue(1, '2');
38$handle2->bindValue(2, '2');
39
40$handle2->execute();
41
42$i = 1;
43print("Handle 2:\n");
44do {
45    print('Rowset ' . $i++ . "\n");
46    if ($handle2->columnCount() > 0)
47        print("Results detected\n");
48} while($handle2->nextRowset());
49
50$handle3 = $db->prepare('UPDATE test_61207 SET id = 2 WHERE id = ?;
51                           SELECT * FROM test_61207 WHERE id = ?;');
52
53$handle3->bindValue(1, '1');
54$handle3->bindValue(2, '2');
55
56$handle3->execute();
57
58$i = 1;
59print("Handle 3:\n");
60do {
61    print('Rowset ' . $i++ . "\n");
62    if ($handle3->columnCount() > 0)
63        print("Results detected\n");
64} while($handle3->nextRowset());
65
66$handle4 = $db->prepare('INSERT INTO test_61207(id) VALUES (3);
67                           UPDATE test_61207 SET id = 2 WHERE id = ?;
68                           SELECT * FROM test_61207 WHERE id = ?;');
69
70$handle4->bindValue(1, '3');
71$handle4->bindValue(2, '2');
72
73$handle4->execute();
74
75$i = 1;
76print("Handle 4:\n");
77do {
78    print('Rowset ' . $i++ . "\n");
79    if ($handle1->columnCount() > 0)
80        print("Results detected\n");
81} while($handle1->nextRowset());
82?>
83--CLEAN--
84<?php
85require_once __DIR__ . '/inc/mysql_pdo_test.inc';
86$db = MySQLPDOTest::factory();
87$db->exec('DROP TABLE IF EXISTS test_61207');
88?>
89--EXPECT--
90Handle 1:
91Rowset 1
92Rowset 2
93Results detected
94Rowset 3
95Handle 2:
96Rowset 1
97Results detected
98Rowset 2
99Handle 3:
100Rowset 1
101Rowset 2
102Results detected
103Handle 4:
104Rowset 1
105Rowset 2
106Rowset 3
107Results detected
108