©
本文档使用
php.cn手册 发布
(PHP 4, PHP 5, PHP 7)
dba_firstkey — Fetch first key
$handle
)dba_firstkey() returns the first key of the database and resets the internal key pointer. This permits a linear search through the whole database.
handle
The database handler, returned by dba_open() or dba_popen() .
Returns the key on success 或者在失败时返回 FALSE
.
[#1] rcracer91 at gmail dot com [2009-08-26 12:21:21]
I wondered why it wasn't already written, so I did because I think working with associative arrays is always as comfortable as can be
<?php
function dba_fetch_assoc($handle) {
$assoc = array();
for($k = dba_firstkey($handle); $k != false; $k = dba_nextkey($handle)) {
$assoc[$k] = dba_fetch($k, $handle);
}
return $assoc;
}
?>
[#2] psycho-logic at excite dot com [2003-10-22 05:38:05]
Looks like Jacky is using some DB object? I don't know if it's native to PHP or written on it's own... Anyways this is what I use:
$DBCon = dba_open("/tmp/test_db.db2", "r", "db2") or die("Uh oh, can't open the database :(");
if ($the_key = dba_firstkey($DBCon)) do {
print("Key: $the_key Value:");
print dba_fetch($the_key, $DBCon);
print("<BR>");
} while ($the_key = dba_nextkey($DBCon));
print ("<BR><BR><BR>Well looks like we're done here :-)");
[#3] jacky dot jackyhung dot net [2002-01-17 05:17:46]
for ($key = dba_firstkey($this->handle); $key !== false; $key = dba_nextkey($this->handle)) {
$keyset[] = $key;
} // end for