summaryrefslogtreecommitdiff
path: root/ext/pdo_mysql/tests/bug80458.phpt
blob: 10bf305d60decc0e957fc39b7394e0ada8433e68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
--TEST--
Bug #80458 PDOStatement::fetchAll() throws for upsert queries
--SKIPIF--
<?php
if (!extension_loaded('pdo') || !extension_loaded('pdo_mysql')) die('skip not loaded');
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'skipif.inc');
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
MySQLPDOTest::skip();
?>
--FILE--
<?php
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');

$db = MySQLPDOTest::factory();
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);

$db->query('DROP TABLE IF EXISTS test');
$db->query('CREATE TABLE test (first int) ENGINE = InnoDB');
$res = $db->query('INSERT INTO test(first) VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14),(15),(16)');
var_dump($res->fetchAll());

$stmt = $db->prepare('DELETE FROM test WHERE first=1');
$stmt->execute();
var_dump($stmt->fetchAll());

$res = $db->query('DELETE FROM test WHERE first=2');
var_dump($res->fetchAll());

$stmt2 = $db->prepare('DELETE FROM test WHERE first=3');
$stmt2->execute();
foreach($stmt2 as $row){
    // expect nothing
}

$stmt3 = $db->prepare('DELETE FROM test WHERE first=4');
$stmt3->execute();
var_dump($stmt3->fetch(PDO::FETCH_ASSOC));

$stmt = $db->prepare('SELECT first FROM test WHERE first=5');
$stmt->execute();
var_dump($stmt->fetchAll());

$db->exec('DROP PROCEDURE IF EXISTS nores');
$db->exec('CREATE PROCEDURE nores() BEGIN DELETE FROM test WHERE first=6; END;');
$stmt4 = $db->prepare('CALL nores()');
$stmt4->execute();
var_dump($stmt4->fetchAll());
$db->exec('DROP PROCEDURE IF EXISTS nores');

$db->exec('DROP PROCEDURE IF EXISTS ret');
$db->exec('CREATE PROCEDURE ret() BEGIN SELECT first FROM test WHERE first=7; END;');
$stmt5 = $db->prepare('CALL ret()');
$stmt5->execute();
var_dump($stmt5->fetchAll());
$stmt5->nextRowset(); // needed to fetch the empty result set of CALL
var_dump($stmt5->fetchAll());
$db->exec('DROP PROCEDURE IF EXISTS ret');

/* With emulated prepares */
print("Emulated prepares\n");
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);

$stmt = $db->prepare('DELETE FROM test WHERE first=8');
$stmt->execute();
var_dump($stmt->fetchAll());

$res = $db->query('DELETE FROM test WHERE first=9');
var_dump($res->fetchAll());

$stmt2 = $db->prepare('DELETE FROM test WHERE first=10');
$stmt2->execute();
foreach($stmt2 as $row){
    // expect nothing
}

$stmt3 = $db->prepare('DELETE FROM test WHERE first=11');
$stmt3->execute();
var_dump($stmt3->fetch(PDO::FETCH_ASSOC));

$stmt = $db->prepare('SELECT first FROM test WHERE first=12');
$stmt->execute();
var_dump($stmt->fetchAll());

$db->exec('DROP PROCEDURE IF EXISTS nores');
$db->exec('CREATE PROCEDURE nores() BEGIN DELETE FROM test WHERE first=13; END;');
$stmt4 = $db->prepare('CALL nores()');
$stmt4->execute();
var_dump($stmt4->fetchAll());
$db->exec('DROP PROCEDURE IF EXISTS nores');

$db->exec('DROP PROCEDURE IF EXISTS ret');
$db->exec('CREATE PROCEDURE ret() BEGIN SELECT first FROM test WHERE first=14; END;');
$stmt5 = $db->prepare('CALL ret()');
$stmt5->execute();
var_dump($stmt5->fetchAll());
$stmt5->nextRowset(); // needed to fetch the empty result set of CALL
var_dump($stmt5->fetchAll());
$db->exec('DROP PROCEDURE IF EXISTS ret');

$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);

$stmt = $db->prepare('DELETE FROM test WHERE first=15');
$stmt->execute();
var_dump($stmt->fetchAll());

$stmt = $db->prepare('SELECT first FROM test WHERE first=16');
$stmt->execute();
var_dump($stmt->fetchAll());

?>
--CLEAN--
<?php
require __DIR__ . '/mysql_pdo_test.inc';
MySQLPDOTest::dropTestTable();
?>
--EXPECT--
array(0) {
}
array(0) {
}
array(0) {
}
bool(false)
array(1) {
  [0]=>
  array(2) {
    ["first"]=>
    string(1) "5"
    [0]=>
    string(1) "5"
  }
}
array(0) {
}
array(1) {
  [0]=>
  array(2) {
    ["first"]=>
    string(1) "7"
    [0]=>
    string(1) "7"
  }
}
array(0) {
}
Emulated prepares
array(0) {
}
array(0) {
}
bool(false)
array(1) {
  [0]=>
  array(2) {
    ["first"]=>
    string(2) "12"
    [0]=>
    string(2) "12"
  }
}
array(0) {
}
array(1) {
  [0]=>
  array(2) {
    ["first"]=>
    string(2) "14"
    [0]=>
    string(2) "14"
  }
}
array(0) {
}
array(0) {
}
array(1) {
  [0]=>
  array(2) {
    ["first"]=>
    string(2) "16"
    [0]=>
    string(2) "16"
  }
}