Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : DBM Functions [deprecated] : dbmnextkey

dbmnextkey

(PHP 4)
string dbmnextkey ( resource dbm_identifier, string key )

Example 486. Visiting every key/value pair in a DBM database

<?php

$key
= dbmfirstkey($dbm_id);
while (
$key) {
   echo
"$key = " . dbmfetch($dbm_id, $key) . "\n";
   
$key = dbmnextkey($dbm_id, $key);
}

?>

Code Examples / Notes » dbmnextkey

fischer

When you have a key "0" or so in your DB, then the example don't works, because "while ($key)" will return false for 0 ...
I had good experiences with "while (strlen($key)>0)" as condition ... because when we have the last key false is returned and false evaluates to "nothing" ...


fred

dbmnext() seems to lose the thread if the program deletes keys as it walks through all rows.  I imagine that something similar happens with inserts.  One way around this is to make two passes:  one to collect the keys and one to manipulate the rows.  For example:
$old_keys = array();
for ($key = dbmfirstkey($db); $key; $key = dbmnextkey($db, $key)) {
 $old_keys[] = $key;
}
while (list($_, $key) = each($old_keys)) {
   dbmdelete($db, $key);
}


hiongun

$key = dbmnextkey($dbm_id, $key) returns
"" on the second call.


karutla

$key = dbmfirstkey($dbm_id);
while ($key) {
   dbmreplace($dbm_id, $value);
   $key = dbmnextkey($dbm_id, $key);
}
doesn't seem to iterate through all the records properly.


Change Language


Follow Navioo On Twitter
dblist
dbmclose
dbmdelete
dbmexists
dbmfetch
dbmfirstkey
dbminsert
dbmnextkey
dbmopen
dbmreplace
eXTReMe Tracker