note 19473 added to ref.dbm

From: Date: Thu, 28 Feb 2002 15:16:53 +0000
Subject: note 19473 added to ref.dbm
Groups: php.notes 
Request: Send a blank email to php-notes+get-27170@lists.php.net to get a copy of this message
First: Make a firstdbm.db file. Set attribute Read and Write. -------------------------------------- <html><body> <? $dbm = dbmopen("firstdbm","w"); echo "<b>\$dbm: $dbm = dbmopen(\"firstdbm\", \"w\");</b>< br>"; echo "<i>".dblist()." = dblist();</i>< br>< br>"; $fruit = "apple"; $colour = "red"; if (dbmexists ($dbm, $fruit)) { $colour = dbmfetch ($dbm, $fruit); echo "\$colour: $colour = dbmfetch(\$dbm: $dbm, \$fruit: $fruit);< br>"; $key = dbmreplace($dbm, $fruit, "green"); echo "\$key: $key = dbmreplace(\$dbm: $dbm, \$fruit: $fruit, \"green\");< br>"; $colour = dbmfetch ($dbm, $fruit); echo "\$colour: $colour = dbmfetch(\$dbm: $dbm, \$fruit: $fruit);< br>"; if ( !dbmdelete($dbm, $fruit) ) { echo "False (OK) = dbmdelete(\$dbm: $dbm, \$fruit: $fruit);< br>"; } else { echo "True (NOT OK) = dbmdelete(\$dbm: $dbm, \$fruit: $fruit);< br>"; } $colour = dbmfetch ($dbm, $fruit); echo "\$color: $colour = dbmfetch(\$dbm: $dbm, \$fruit: $fruit);< br><hr>"; $i = 1; $key = dbmfirstkey($dbm); while ($key) { if ($i==1) { echo "\$key: $key = dbmfirstkey(\$dbm: $dbm);< br>"; } else { echo "\$key: $key = dbmnextkey(\$dbm: $dbm);< br>"; } $i++; $colour = dbmfetch ($dbm, $key); echo "\$colour: $colour = dbmfetch(\$dbm: $dbm, \$key: $key);< br>"; $key = dbmnextkey($dbm,$key); } } else { dbminsert ($dbm, $fruit, $colour); echo "dbminsert(\$dbm: $dbm, \$fruit: $fruit, \$colour: $colour);< br>"; dbminsert ($dbm, "pear", "yellow"); echo "dbminsert(\$dbm: $dbm, \"pear\", \"yellow\");< br>"; dbminsert ($dbm, "apricot", "pink"); echo "dbminsert(\$dbm: $dbm, \"apricot\", \"pink\");< br><hr>"; $i = 1; $key = dbmfirstkey($dbm); while ($key) { if ($i==1) { echo "\$key: $key = dbmfirstkey(\$dbm: $dbm);< br>"; } else { echo "\$key: $key = dbmnextkey(\$dbm: $dbm);< br>"; } $i++; $colour = dbmfetch ($dbm, $key); echo "\$colour: $colour = dbmfetch(\$dbm: $dbm, \$key: $key);< br>"; $key = dbmnextkey($dbm,$key); } } echo "< br>"; if (dbmclose ($dbm)) { echo "<b>True (OK) = dbmclose(\$dbm: $dbm);</b>< br>"; } else { echo "<b>False (NOT OK) = dbmclose(\$dbm: $dbm);</b>< br>"; }; ?> </body></html> -------------------------------------- The first run output: $dbm: 1 = dbmopen("firstdbm", "w"); ndbm support enabled = dblist(); dbminsert($dbm: 1, $fruit: apple, $colour: red); dbminsert($dbm: 1, "pear", "yellow"); dbminsert($dbm: 1, "apricot", "pink"); $key: pear = dbmfirstkey($dbm: 1); $colour: yellow = dbmfetch($dbm: 1, $key: pear); $key: apricot = dbmnextkey($dbm: 1); $colour: pink = dbmfetch($dbm: 1, $key: apricot); $key: apple = dbmnextkey($dbm: 1); $colour: red = dbmfetch($dbm: 1, $key: apple); True (OK) = dbmclose($dbm: 1); -------------------------------------- The second run output: $dbm: 1 = dbmopen("firstdbm", "w"); ndbm support enabled = dblist(); $colour: red = dbmfetch($dbm: 1, $fruit: apple); $key: 0 = dbmreplace($dbm: 1, $fruit: apple, "green"); $colour: green = dbmfetch($dbm: 1, $fruit: apple); False (OK) = dbmdelete($dbm: 1, $fruit: apple); $color: = dbmfetch($dbm: 1, $fruit: apple); $key: pear = dbmfirstkey($dbm: 1); $colour: yellow = dbmfetch($dbm: 1, $key: pear); $key: apricot = dbmnextkey($dbm: 1); $colour: pink = dbmfetch($dbm: 1, $key: apricot); True (OK) = dbmclose($dbm: 1); -- http://www.php.net/manual/en/ref.dbm.php http://master.php.net/manage/user-notes.php?action=edit+19473 http://master.php.net/manage/user-notes.php?action=delete+19473 http://master.php.net/manage/user-notes.php?action=reject+19473

« previous php.notes (#27170) next »