1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
<?php
##
## Copyright (c) 1999 Guarneri Carmelo <carmelo@melting-soft.com>
##
## $Id: ct_dba.inc,v 1.2 1999/10/28 11:14:53 carmelo Exp $
##
## PHPLIB Data Storage Container using DBM Files with Database abstraction layer functions
##
## Code inspired by ct_dbm.inc v 1.1
class CT_Dba {
##
## Define these parameters by overwriting or by
## deriving your own class from it (recommened)
##
var $dba_handler = "gdbm"; ## either dbm, gdbm, ndbm, cdb, db2
## the handler must be compiled in php
var $dbm_file = ""; ## PREEXISTING DBM File
## writable by the web server UID
## end of configuration
var $dbaid; ## our dbm resource handle
function ac_start() {
# Open DBM file for write access
$this->dbaid=dba_open($this->dbm_file, "w", $this->dba_handler);
}
function ac_get_lock() {
# Not needed in this instance
}
function ac_release_lock() {
# Not needed in this instance
dba_close($this->dbaid);
}
function ac_newid($str, $name) {
return $str;
}
function ac_store($id, $name, $str) {
dba_replace("$id$name", urlencode($str).";".time(), $this->dbaid);
return true;
}
function ac_delete($id, $name) {
dba_delete( "$id$name", $this->dbaid);
}
function ac_gc($gc_time, $name) {
$cmp = time() - $gc_time * 60;
$i = dba_firstkey($this->dbaid);
while ($i) {
$val = @dba_fetch( $i, $this->dbaid);
$dat = explode(";", $val);
if(strcmp($dat[1], $cmp) < 0) {
dba_delete( $i, $this->dbaid);
}
$i = dba_nextkey($this->dbaid);
}
}
function ac_halt($s) {
echo "<b>$s</b>";
exit;
}
function ac_get_value($id, $name) {
$dat = explode(";", dba_fetch( "$id$name", $this->dbaid));
return urldecode($dat[0]);
}
}
?>
|