Problems writing & inserting into DBM files

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Skyjuice
Forum Newbie
Posts: 3
Joined: Tue Sep 03, 2002 6:10 pm

Problems writing & inserting into DBM files

Post by Skyjuice »

My dba_open() seems to work fine. And everything is fine but when I insert records into the DBM file, nothing is entered.

This is made worse by the fact that there are no errors or warnings. It just doesn't write anything into the files. When I try to create a new DBM file it also gives a positive return code without creating anything.

I am running on:

Windows NT 5.0 build 2195
Apache/1.3.24
DB3 enabled

This is really confusing as I expected some error or warning.

My script is as follows:

if (file_exists($file_name))
{
echo "DBA file found:".$file_name."\n";
echo "Opening with write only dba file:".$file_name."\n";
$db_id = dba_open($file_name, "w", $handler_name);
if (!$db_id)
{
echo "Failed opening existing dba file:".$file_name."\n";
}
else
{
echo "Succeeded opening existing dba file:".$file_name."\n";
echo "Checking existence of user id:".$user_id.$user_pwd."\n";
if (dba_exists ($user_id, $db_id))
{
echo "Confirmed existence of user id:".$user_id.$user_pwd."\n";
echo dba_fetch ($user_id, $db_id);
$last_seen = dba_fetch ($user_id, time(), $db_id);
dba_delete ($user_id, $db_id);
}
else
{
echo "Confirmed non-existence of user id:".$user_id.$user_pwd."\n";
echo "Now inserting user details:".$user_id.$user_pwd."\n";
dba_insert("UserId", $user_id.$user_pwd, $db_id);
}
}
}
else
{
echo "DBA file not found:".$file_name."\n";
echo "Opening with truncate read/write dba file:".$file_name."\n";
$db_id = dba_open($file_name, "n", $handler_name);
if (!$db_id)
{
echo "Failed creating new dba file:".$file_name."\n";
}
else
{
echo "Succeeded creating new dba file:".$file_name."\n";
echo "Now inserting user details:".$user_id.$user_pwd."\n";
dba_insert("UserId", $user_id.$user_pwd, $db_id);
}
}

dba_close($db_id);
Post Reply