Back to index

php5  5.3.10
dba_handler.inc
Go to the documentation of this file.
00001 <?php
00002 
00003 echo "database handler: $handler\n";
00004 
00005 do {
00006        if (($db_file = dba_open($db_filename, 'n'.$lock_flag, $handler))!==FALSE) {
00007               dba_insert("key1", "Content String 1", $db_file);
00008               dba_insert("key2", "Content String 2", $db_file);
00009               dba_insert("key3", "Third Content String", $db_file);
00010               dba_insert("key4", "Another Content String", $db_file);
00011               dba_insert("key5", "The last content string", $db_file);
00012               if ($handler != 'cdb') {
00013                      dba_delete("key3", $db_file);
00014                      dba_delete("key1", $db_file);
00015               } else {
00016                      dba_close($db_file);
00017                      if (($db_file = dba_open($db_filename, 'r'.$lock_flag, $handler))===FALSE) {
00018                             echo "Error reopening database\n";
00019                      }
00020               }
00021               $a = dba_firstkey($db_file);
00022               $i=0;
00023               while($a) {
00024                      $a = dba_nextkey($db_file);
00025                      $i++;
00026               }
00027               echo $i;
00028               for ($i=1; $i<6; $i++) {
00029                      echo dba_exists("key$i", $db_file) ? "Y" : "N";
00030               }
00031               echo "\n";
00032               echo dba_fetch("key2", $db_file)."\n";
00033               if ($handler != 'cdb') {
00034                      dba_replace("key2", "Content 2 replaced", $db_file);
00035                      echo dba_fetch("key2", $db_file)."\n";
00036               }
00037               dba_close($db_file);
00038        } else {
00039               echo "Error creating database\n";
00040        }
00041        if ($handler != 'cdb') {
00042               $db_writer = dba_open($db_filename, 'c'.$lock_flag, $handler);
00043               if (($dba_reader = @dba_open($db_filename, 'r'.$lock_flag.($lock_flag ? 't' : ''), $handler))===false) {
00044                      echo "Read during write: not allowed\n";
00045               } else {
00046                      echo "Read during write: allowed\n";
00047               }
00048               if ($db_writer!==FALSE) {
00049                      dba_insert("key number 6", "The 6th value", $db_writer);
00050                      @dba_insert("key number 6", "The 6th value inserted again would be an error", $db_writer);
00051                      dba_replace("key2", "Content 2 replaced 2nd time", $db_writer);
00052                      dba_delete("key4", $db_writer);
00053                      echo dba_fetch("key2", $db_writer)."\n";
00054                      echo dba_fetch("key number 6", $db_writer)."\n";
00055                      dba_close($db_writer); // when the writer is open at least db3 would fail because of buffered io.
00056               } else {
00057                      die("Error reopening database\n");
00058               }
00059        }
00060        if (($db_file = dba_open($db_filename, 'r'.$lock_flag, $handler))!==FALSE) {
00061               $key = dba_firstkey($db_file);
00062               $res = array();
00063               while($key) {
00064                      $res[$key] = dba_fetch($key, $db_file);
00065                      $key = dba_nextkey($db_file);
00066               }
00067               ksort($res);
00068               var_dump($res);
00069               dba_close($db_file);
00070        } else {
00071               echo "Error reading database\n";
00072        }
00073        if (!empty($dba_reader)) {
00074               dba_close($dba_reader);
00075        }
00076        if (($db_file = dba_popen($db_filename, 'r'.($lock_flag==''?'':'-'), $handler))!==FALSE) {
00077               if ($handler == 'dbm') {
00078                      dba_close($db_file);
00079               }
00080        }
00081 
00082        if ($lock_flag == '') {
00083               break;
00084        } else {
00085               echo "--NO-LOCK--\n";
00086               $lock_flag = '';
00087        }
00088 } while(1);
00089 
00090 ?>