xref: /PHP-8.3/ext/dba/tests/dba_cdb_read.phpt (revision 134441ef)
1--TEST--
2DBA CDB handler test (read only)
3--EXTENSIONS--
4dba
5--SKIPIF--
6<?php
7require_once __DIR__ . '/setup/setup_dba_tests.inc';
8check_skip('cdb_make');
9?>
10--CONFLICTS--
11test.cdb
12--FILE--
13<?php
14    echo "database handler: cdb\n";
15    $handler = 'cdb';
16    $db_file = __DIR__.'/test.cdb';
17    if (($db_file=dba_open($db_file, "r", $handler))!==FALSE) {
18        // read key sequence
19        $a = dba_firstkey($db_file);
20        $count= 0;
21        $keys = $a;
22        while($a) {
23            $a = dba_nextkey($db_file);
24            $keys .= $a;
25            $count++;
26        }
27        // display number of entries and key existence
28        echo $count;
29        for ($i=1; $i<8; $i++) {
30            echo dba_exists($i, $db_file) ? "Y" : "N";
31        }
32        echo "\n=";
33        echo dba_fetch(1, $db_file);
34        echo dba_fetch(2, $db_file);
35        echo dba_fetch(3, $db_file);
36        echo dba_fetch(4, $db_file);
37        echo "\n#";
38        echo dba_fetch(1, $db_file);
39        echo dba_fetch(1, $db_file);
40        echo dba_fetch(2, $db_file);
41        echo dba_fetch(2, $db_file);
42        echo "\n?".$keys;
43        // with skip = 0 dba_fetch must fetch the first result
44        echo "\n#";
45        $skip = array();
46        for ($i=0; $i < strlen($keys); $i++) {
47            $key = substr($keys, $i, 1);
48            $skip[$key] = 0;
49            echo dba_fetch($key, $db_file);
50        }
51        echo "\n=";
52        for ($i=0; $i < strlen($keys); $i++) {
53            $key = substr($keys, $i, 1);
54            echo dba_fetch($key, $db_file, $skip[$key]);
55            $skip[$key]++;
56        }
57        dba_close($db_file);
58    } else {
59        echo "Error creating database\n";
60    }
61?>
62--EXPECT--
63database handler: cdb
647YYYYNNN
65=1234
66#1122
67?1212314
68#1212314
69=1231324
70