php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #20294 dba_firstkey doesn't work at all with Berkeley DB3 files
Submitted: 2002-11-06 22:04 UTC Modified: 2002-11-06 22:30 UTC
From: JArmistead at mail dot com Assigned:
Status: Not a bug Package: DBM/DBA related
PHP Version: 4.2.2 OS: Solaris 2.5.1
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: JArmistead at mail dot com
New email:
PHP Version: OS:

 

 [2002-11-06 22:04 UTC] JArmistead at mail dot com
Here is some sample source:

<?
        // ** Write to database **
        $dbh = dba_open("/tmp/test.db3","c","db3");
        for($x=0;$x<500;$x++)
        {
                $key = strval($x);
                $value = "test" . $key;
                $res = dba_insert($key,$value,$dbh);

// Debug
if(!$res) echo "Failed to add rec $x<br>";

        }
        dba_close($dbh);
        echo "Done adding<br>";

        // ** Read back **
        echo "Read back<br>";
        $dbh = dba_open("/tmp/test.db3","r","db3");
        if ($dbh == false)
        {
         echo "Database failed to open<BR>";
        }
        $key = dba_firstkey($dbh);
        if ($key == false)
        {
         echo "Unable to use dba_firstkey to find initial key<BR>";
        }
        echo "First key is $key<BR>";
        $x=0;
        while($key != false)
        {
                $value = dba_fetch($key,$dbh);
                echo "$key,$value<br>";
                $key = dba_nextkey($dbh);
                $x++;
        }
        dba_close($dbh);
        echo "Finished ! ($x records read back)<br>";
?>

Berkeley-DB is version 3.3.11
C Compiler is GNU C 2.95.3
Apache HTTPD is V2.0.40

PHP configured by

'./configure' '--with-apxs2=/usr/local/apache2/bin/apxs' '--with-db3=/usr/local/BerkeleyDB.3.3' 

Basically, it's writing 500 records to the DB3 file (I can cat it and see the resultant output) and then trying to read them back.  Not one record is read back because db_firstkey returns FALSE.

Help appreciated

Jason

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-11-06 22:10 UTC] JArmistead at mail dot com
Silly me, fancy using an initial key of zero (0).  This is indistinguishable from the FALSE value (a real TRAP for new players like me !!!).  Changing the bounds of the variable "X" ensured that it read back the key / value pairs correctly.

Bogus !!!
 [2002-11-06 22:30 UTC] rasmus@php.net
Not indistinguishable.  False and 0 are distinct values easily distinguished by using the === operator.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 10:01:29 2024 UTC