xref: /PHP-8.0/ext/pdo/tests/pdo_031.phpt (revision f8d79582)
1--TEST--
2PDO Common: PDOStatement SPL iterator
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
16$data = array(
17    array('10', 'Abc', 'zxy'),
18    array('20', 'Def', 'wvu'),
19    array('30', 'Ghi', 'tsr'),
20);
21
22$db = PDOTest::factory();
23
24$db->exec('CREATE TABLE test(id INT NOT NULL PRIMARY KEY, val VARCHAR(10), val2 VARCHAR(16))');
25
26$stmt = $db->prepare("INSERT INTO test VALUES(?, ?, ?)");
27foreach ($data as $row) {
28    $stmt->execute($row);
29}
30
31unset($stmt);
32
33echo "===QUERY===\n";
34
35$stmt = $db->query('SELECT * FROM test');
36
37foreach(new RecursiveTreeIterator(new RecursiveArrayIterator($stmt->fetchAll(PDO::FETCH_ASSOC)), RecursiveTreeIterator::BYPASS_KEY) as $c=>$v)
38{
39    echo "$v [$c]\n";
40}
41
42echo "===DONE===\n";
43exit(0);
44?>
45--EXPECT--
46===QUERY===
47|-Array [0]
48| |-10 [id]
49| |-Abc [val]
50| \-zxy [val2]
51|-Array [1]
52| |-20 [id]
53| |-Def [val]
54| \-wvu [val2]
55\-Array [2]
56  |-30 [id]
57  |-Ghi [val]
58  \-tsr [val2]
59===DONE===
60