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