xref: /PHP-8.1/ext/dba/tests/dba_db4_016.phpt (revision b5a14e6c)
1--TEST--
2DBA DB4 File Creation popen("c") with existing valid file
3--EXTENSIONS--
4dba
5--SKIPIF--
6<?php
7$handler = "db4";
8require_once(__DIR__ .'/skipif.inc');
9die("info $HND handler used");
10?>
11--FILE--
12<?php
13
14$handler = "db4";
15require_once(__DIR__ .'/test.inc');
16echo "database handler: $handler\n";
17
18if (($db_file = dba_popen($db_filename, "c", $handler)) !== FALSE) {
19    if (file_exists($db_filename)) {
20        echo "database file created\n";
21        var_dump(dba_insert("key1", "This is a test insert", $db_file));
22        echo dba_fetch("key1", $db_file), "\n";
23        dba_close($db_file);
24    } else {
25        echo "File did not get created\n";
26    }
27} else {
28    echo "Error creating $db_filename\n";
29}
30
31// Now test reopening it
32if (($db_file = dba_popen($db_filename, "c", $handler)) !== FALSE) {
33    if (file_exists($db_filename)) {
34        echo "database file created\n";
35        var_dump(dba_insert("key1", "second open test", $db_file));
36        var_dump(dba_insert("key2", "second open test row 2", $db_file));
37        echo dba_fetch("key1", $db_file), "\n";
38        echo dba_fetch("key2", $db_file), "\n";
39        dba_close($db_file);
40    } else {
41        echo "File did not get created\n";
42    }
43} else {
44    echo "Error creating $db_filename\n";
45}
46
47?>
48--CLEAN--
49<?php
50require(__DIR__ .'/clean.inc');
51?>
52--EXPECT--
53database handler: db4
54database file created
55bool(true)
56This is a test insert
57database file created
58bool(false)
59bool(true)
60This is a test insert
61second open test row 2
62