summaryrefslogtreecommitdiff
path: root/ext/pdo/tests/pdo_016.phpt
blob: 6879faa5b90f316402be64ca21860c73d5003d03 (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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
--TEST--
PDO Common: PDO::FETCH_BOUND
--SKIPIF--
<?php
if (!extension_loaded('pdo')) die('skip');
$dir = getenv('REDIR_TEST_DIR');
if (false == $dir) die('skip no driver');
if (!strncasecmp(getenv('PDOTEST_DSN'), 'oci', strlen('oci'))) die('skip not relevant for oci driver - cannot reexecute after closing cursors without reparse');
require_once $dir . 'pdo_test.inc';
PDOTest::skip();
?>
--FILE--
<?php
if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.__DIR__ . '/../../pdo/tests/');
require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
$db = PDOTest::factory();

if ($db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'mysql') {
	$db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
}

$db->exec('CREATE TABLE test(idx int NOT NULL PRIMARY KEY, txt VARCHAR(20))');
$db->exec('INSERT INTO test VALUES(0, \'String0\')');
$db->exec('INSERT INTO test VALUES(1, \'String1\')');
$db->exec('INSERT INTO test VALUES(2, \'String2\')');

$stmt1 = $db->prepare('SELECT COUNT(idx) FROM test');
$stmt2 = $db->prepare('SELECT idx, txt FROM test ORDER by idx');

$stmt1->execute();
var_dump($stmt1->fetchColumn());
$stmt1 = null;

$stmt2->execute();
$cont = $stmt2->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_UNIQUE);
var_dump($cont);

echo "===WHILE===\n";

$stmt2->bindColumn('idx', $idx);
$stmt2->bindColumn('txt', $txt);
$stmt2->execute();

while($stmt2->fetch(PDO::FETCH_BOUND)) {
	var_dump(array($idx=>$txt));
}

echo "===ALONE===\n";

$stmt3 = $db->prepare('SELECT txt FROM test WHERE idx=:inp');
$stmt3->bindParam(':inp', $idx); /* by foreign name */

$stmt4 = $db->prepare('SELECT idx FROM test WHERE txt=:txt');
$stmt4->bindParam(':txt', $txt);  /* using same name */

foreach($cont as $idx => $txt)
{
	var_dump(array($idx=>$txt));
	var_dump($stmt3->execute());

	if ($idx == 0) {
		/* portability-wise, you may only bindColumn()s
		 * after execute() has been called at least once */
		$stmt3->bindColumn('txt', $col1);
	}
	var_dump($stmt3->fetch(PDO::FETCH_BOUND));
	$stmt3->closeCursor();

	var_dump($stmt4->execute());
	if ($idx == 0) {
		/* portability-wise, you may only bindColumn()s
		 * after execute() has been called at least once */
		$stmt4->bindColumn('idx', $col2);
	}
	var_dump($stmt4->fetch(PDO::FETCH_BOUND));
	$stmt4->closeCursor();
	var_dump(array($col2=>$col1));
}

echo "===REBIND/SAME===\n";

$stmt4->bindColumn('idx', $col1);

foreach($cont as $idx => $txt)
{
	var_dump(array($idx=>$txt));
	var_dump($stmt3->execute());
	var_dump($stmt3->fetch(PDO::FETCH_BOUND));
	$stmt3->closeCursor();
	var_dump($col1);
	var_dump($stmt4->execute());
	var_dump($stmt4->fetch(PDO::FETCH_BOUND));
	$stmt4->closeCursor();
	var_dump($col1);
}

echo "===REBIND/CONFLICT===\n";

$stmt2->bindColumn('idx', $col1);
$stmt2->bindColumn('txt', $col1);
$stmt2->execute();

while($stmt2->fetch(PDO::FETCH_BOUND))
{
	var_dump($col1);
}


?>
--EXPECT--
string(1) "3"
array(3) {
  [0]=>
  string(7) "String0"
  [1]=>
  string(7) "String1"
  [2]=>
  string(7) "String2"
}
===WHILE===
array(1) {
  [0]=>
  string(7) "String0"
}
array(1) {
  [1]=>
  string(7) "String1"
}
array(1) {
  [2]=>
  string(7) "String2"
}
===ALONE===
array(1) {
  [0]=>
  string(7) "String0"
}
bool(true)
bool(true)
bool(true)
bool(true)
array(1) {
  [0]=>
  string(7) "String0"
}
array(1) {
  [1]=>
  string(7) "String1"
}
bool(true)
bool(true)
bool(true)
bool(true)
array(1) {
  [1]=>
  string(7) "String1"
}
array(1) {
  [2]=>
  string(7) "String2"
}
bool(true)
bool(true)
bool(true)
bool(true)
array(1) {
  [2]=>
  string(7) "String2"
}
===REBIND/SAME===
array(1) {
  [0]=>
  string(7) "String0"
}
bool(true)
bool(true)
string(7) "String0"
bool(true)
bool(true)
string(1) "0"
array(1) {
  [1]=>
  string(7) "String1"
}
bool(true)
bool(true)
string(7) "String1"
bool(true)
bool(true)
string(1) "1"
array(1) {
  [2]=>
  string(7) "String2"
}
bool(true)
bool(true)
string(7) "String2"
bool(true)
bool(true)
string(1) "2"
===REBIND/CONFLICT===
string(7) "String0"
string(7) "String1"
string(7) "String2"