xref: /PHP-7.2/ext/spl/examples/dba_array.php (revision 60a69dae)
1<?php
2
3/** @file   dba_array.php
4 * @brief   Program DBA array utility
5 * @ingroup Examples
6 * @author  Marcus Boerger
7 * @date    2003 - 2005
8 *
9 * Usage php dba_array.php \<file\> \<handler\> \<key\> [\<value\>]
10 *
11 * If \<value\> is specified then \<key\> is set to \<value\> in \<file\>.
12 * Else the value of \<key\> is printed only.
13 *
14 * Note: configure with --enable-dba
15 */
16
17if ($argc < 4) {
18	echo <<<EOF
19Usage: php ${_SERVER['PHP_SELF']} <file> <handler> <key> [<value>]
20
21If <value> is specified then <key> is set to <value> in <file>.
22Else the value of <key> is printed only.
23
24
25EOF;
26	exit(1);
27}
28
29if (!class_exists("DbaReader", false)) require_once("dbareader.inc");
30
31try {
32	if ($argc > 2) {
33		$dba = new DbaArray($argv[1], $argv[2]);
34		if ($dba && $argc > 3) {
35			if ($argc > 4) {
36				$dba[$argv[3]] = $argv[4];
37			}
38			var_dump(array('Index' => $argv[3], 'Value' => $dba[$argv[3]]));
39		}
40		unset($dba);
41	}
42	else
43	{
44		echo "Not enough parameters\n";
45		exit(1);
46	}
47}
48catch (exception $err) {
49	var_dump($err);
50	exit(1);
51}
52?>
53