xref: /PHP-8.0/ext/pdo/tests/pdo_019.phpt (revision f8d79582)
1--TEST--
2PDO Common: fetch() and while()
3--SKIPIF--
4<?php
5if (!extension_loaded('pdo')) die('skip');
6$dir = getenv('REDIR_TEST_DIR');
7if (false == $dir) die('skip no driver');
8require_once $dir . 'pdo_test.inc';
9PDOTest::skip();
10?>
11--FILE--
12<?php
13if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.__DIR__ . '/../../pdo/tests/');
14require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
15$db = PDOTest::factory();
16
17$db->exec('CREATE TABLE test(idx int NOT NULL PRIMARY KEY, txt VARCHAR(20))');
18$db->exec('INSERT INTO test VALUES(0, \'String0\')');
19$db->exec('INSERT INTO test VALUES(1, \'String1\')');
20$db->exec('INSERT INTO test VALUES(2, \'String2\')');
21$db->exec('INSERT INTO test VALUES(3, \'String3\')');
22
23
24var_dump($db->query('SELECT COUNT(*) FROM test')->fetchColumn());
25
26$stmt = $db->prepare('SELECT idx, txt FROM test ORDER by idx');
27
28$stmt->execute();
29$cont = $stmt->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_UNIQUE);
30var_dump($cont);
31
32echo "===WHILE===\n";
33
34$stmt->bindColumn('idx', $idx);
35$stmt->bindColumn('txt', $txt);
36$stmt->execute();
37
38while($stmt->fetch(PDO::FETCH_BOUND)) {
39    var_dump(array($idx=>$txt));
40}
41
42?>
43--EXPECT--
44string(1) "4"
45array(4) {
46  [0]=>
47  string(7) "String0"
48  [1]=>
49  string(7) "String1"
50  [2]=>
51  string(7) "String2"
52  [3]=>
53  string(7) "String3"
54}
55===WHILE===
56array(1) {
57  [0]=>
58  string(7) "String0"
59}
60array(1) {
61  [1]=>
62  string(7) "String1"
63}
64array(1) {
65  [2]=>
66  string(7) "String2"
67}
68array(1) {
69  [3]=>
70  string(7) "String3"
71}
72