Storing structured data in a DBM database : DBM « MySQL Database « PHP






Storing structured data in a DBM database

 
<?php
$dbh = dba_open('users.db','c','gdbm') or die($php_errormsg);

if ($exists = dba_exists($_POST['username'], $dbh)) {
    $serialized_data = dba_fetch($_POST['username'], $dbh) or die($php_errormsg);
    $data = unserialize($serialized_data);
} else {
    $data = array();
}

if ($_POST['new_password']) {
    $data['password'] = $_POST['new_password'];
}
$data['last_access'] = time();

if ($exists) {
    dba_replace($_POST['username'],serialize($data), $dbh);
} else {
    dba_insert($_POST['username'],serialize($data), $dbh);
}

dba_close($dbh);
?>
  
  








Related examples in the same category

1.Calculating password length with DBM
2.Tracking users and passwords with a DBM database