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