PHP Conference Nagoya 2025

dba_firstkey

(PHP 4, PHP 5, PHP 7, PHP 8)

dba_firstkey获取第一个键

说明

dba_firstkey(Dba\Connection $dba): string|false

dba_firstkey() 返回数据库的第一个键并重置内部键指针。 这允许通过整个数据库进行线性搜索。

参数

dba

一个由 dba_open()dba_popen() 返回的 Dba\Connection 实例。

返回值

成功时返回键, 或者在失败时返回 false

更新日志

版本 说明
8.4.0 dba 参数现在接受 Dba\Connection 实例, 之前接受有效的 dba resource

参见

添加备注

用户贡献的备注 3 notes

up
0
jacky dot jackyhung dot net
22 years ago
for ($key = dba_firstkey($this->handle); $key !== false; $key = dba_nextkey($this->handle)) {
$keyset[] = $key;
} // end for
up
-1
rcracer91 at gmail dot com
15 years ago
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;
}
?>
up
-1
psycho-logic at excite dot com
21 years ago
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 :-)");
To Top