|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #9283 Serialized data gets corrupted in DBM
Submitted: 2001-02-15 11:53 UTC Modified: 2002-05-22 00:00 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: sam at 2bhox dot com Assigned:
Status: No Feedback Package: DBM/DBA related
PHP Version: 4.0.4pl1 OS: Windows 98
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2001-02-15 11:53 UTC] sam at 2bhox dot com
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 );
    { $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!


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-04-19 01:21 UTC]
can you try again to reproduce this using php4.2.0RC4?

 [2002-05-22 00:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2003-05-20 23:56 UTC] adam at saki dot com dot au
I have seen the exact same problem on a DG Aviion (DG/UX) system using PHP 4.2.3.  Also the file was dba not dbm so I suspect it is the serializer, not the file access code.  Apart from that the symptoms were the same.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Mon May 23 15:05:45 2022 UTC