dba_array.php 1.0 KB

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