php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #11394 PHP does not read from or write to flat file properly
Submitted: 2001-06-11 02:47 UTC Modified: 2001-06-12 03:25 UTC
From: ridley at net2000 dot com dot au Assigned:
Status: Closed Package: DBM/DBA related
PHP Version: 4.0.5 OS: Win98 (2nd ed, 4.10.2222.A)
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ridley at net2000 dot com dot au
New email:
PHP Version: OS:

 

 [2001-06-11 02:47 UTC] ridley at net2000 dot com dot au
I am new to php and DBMs, and I have trouble reading from (or writing to) the DBM flat file.

Other possibly related bugs: Bug id #9222 and #9283

The writer code:
    <?PHP
      $fn = "./DBMData/products";
      $dbh = dbmopen($fn,"c") or die ("Couldn't open test DBM");

      $item="Screwdriver";
      $item_p="12.34";
      if (dbmexists ($dbh, $item)) {
        dbmreplace($dbh, $item, $item_p);
        } else {
        dbminsert ($dbh, $item, $item_p);
      }
      $item="Tricorder";
      $item_p="2.34";
      if (dbmexists ($dbh, $item)) {
        dbmreplace($dbh, $item, $item_p);
        } else {
        dbminsert ($dbh, $item, $item_p);
      }
      $item="ORAC";
      $item_p="98.76";
      if (dbmexists ($dbh, $item)) {
        dbmreplace($dbh, $item, $item_p);
        } else {
        dbminsert ($dbh, $item, $item_p);
      }
      $item="HAL 2000";
      $item_p="99.97";
      if (dbmexists ($dbh, $item)) {
        dbmreplace($dbh, $item, $item_p);
        } else {
        dbminsert ($dbh, $item, $item_p);
      }
      dbmclose($dbh);
    ?>

The DBM file created:
11
Screwdriver5
12.349
Tricorder4
2.344
ORAC5
98.768
HAL 20005
99.97

The reader code:
      <?PHP
        $fn = "./DBMData/products";
        $dbh = dbmopen($fn,"c") or die ("Couldn't open test DBM");
        $key = dbmfirstkey($dbh);
        while ($key != "")
        {
          $value = dbmfetch($dbh, $key);
          print "<TR>";
            print "<TD ALIGN=\"left\">$key</TD>";
            print "<TD ALIGN=\"right\">\$$value</TD>";
          print "</TR>\n";
          $key = dbmnextkey($dbh, $key);
        }
        dbmclose($dbh);
      ?>

The output:
crewdriver5     $
Tricorder       $2.34
ORAC            $98.76
HAL 2000        $9.972

Thanks in advace,
Ridley

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-06-12 03:25 UTC] sniper@php.net
The db extension (dbm) is deprecated and not developed
anymore. You should try using the dba extension instead.
Please try it and if this happens with it too, reopen.

--Jani

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 23:01:28 2024 UTC