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