Operating system: Windows 98
PHP version:      4.0.4pl1
Description:  Serialized data gets corrupted in DBM

I created a set of programs for maintaining userid and password information
using the DBM functions. (dbmopen, dbminsert, etc).. I keep userid,
password, effective date, expiry dates, etc... Hence I need to keep more
than just name & password pairs... I use the userid as the name and the
value is a serialized variable containing an associative array of the
remaining fields...

My PHP programs to add and display the user records works - unfortunately it
works intermittently... Some time all records are written correctly and are
displayed correctly.. but sometime several are written but when are
displayed, the details of the serialized data are missing.. it seems to be
corrupted...

I attach some code for the dbminsert and dbmfetch here...

Notes: $user is an associative array containing the password, start dates,
etc.

function addUser( $dbName, &$dbStatus,  $userid, $user ) {
  $dbh = dbmopen( "$dbName", "w" )
         or die("Couldn't open $dbName database");
  $serial_user = serialize( $user );
  print "serial_user is equal to <br> $serial_user <br>";
  $dbStatus = dbminsert( $dbh, "$userid", "$serial_user" );
  dbmclose( $dbh );
  }

function getUser( $dbName, &$dbStatus, $userid ) {
  $dbh = dbmopen( "$dbName", "r" )  // --- read db ----
         or die("Couldn't open $dbName database");
  if ( dbmexists( $dbh, $userid ) )
    {
    $serial_user = dbmfetch( $dbh, $userid );
    print "serial_user is equal to <br> $serial_user <br>";
    $user = unserialize( $serial_user );
    }
  else
    { $dbStatus = -1; }
  dbmclose( $dbh );
  return $user;
  }

I looked at the dbm file itself using a text editor and all the data are
present, even for those records that shows blanks for the details.

I opened 2 Internet Explorer windows side by side and ran the insert program
on one and the display on the other. I displayed the serialized value (i.e.
$serial_user) on both windows...

In the add window, the serialized data always looks like this:
a:5:{s:4:"name;s:1:"a";s:3:"pwd.... ETC ETC...

In the display window, the serialized data also looked as above when the
data is displayed correctly...

However, when the data is 'missing' the serialized data looks like this
:5:{s:4:"name;s:1:"a";s:3:"pwd.... ETC ETC...
(i.e. the 'a' is missing).

(you can see my debugging print statements in the code that I attached
above).

I am running PHP on Apache Web Server (1.3.14) for Windows. Both the browser
client and the Apache server are running on the same PC.

Thanks in advance for your help!




-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to