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