phpday 2027 - Call for Papers

dba_fetch

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

dba_fetch — Fetch data specified by key

Description

function dba_fetch(string|array $key, Dba\Connection $dba, int $skip = 0): string|false

Overloaded signature deprecated as of 8.3.0:

function dba_fetch(string|array $key, int $skip, Dba\Connection $dba): string|false

dba_fetch() fetches the data specified by key from the database specified with dba.

Parameters

key

The key the data is specified by.

Note:

When working with inifiles this function accepts arrays as keys where index 0 is the group and index 1 is the value name. See: dba_key_split().

dba

A Dba\Connection instance, returned by dba_open() or dba_popen().

skip

The number of entries with the same key to skip before the one that is returned. Only the cdb and inifile handlers support it. With any other handler, a non-zero value is ignored and an E_NOTICE is raised.

With cdb, a negative value is treated as 0. With inifile, a value below -1 is treated as 0. In both cases, an E_NOTICE is raised.

Return Values

Returns the associated string if the key/data pair is found, false otherwise.

Changelog

Version Description
8.4.0 The dba parameter expects a Dba\Connection instance now; previously, a valid dba resource was expected.
8.3.0 Calling dba_fetch() with dba as the 3rd argument is now deprecated.
8.2.0 dba_fetch()'s optional skip argument is now at the end in line with PHP userland semantics. The previously overloaded signature is still accepted but discouraged.

See Also

User Contributed Notes 1 note

up
4
khan666 at lycos dot co dot kr
15 years ago
:: fetch array sort.

ex) TEST_DATA.DB

    1/korea/5000/word 1
    10/japan/25000/word 10
    21/china/130000/word 21
    2/usa/35000/word 2

<?php
# LIST SORT 
$DB4_DATABASE = "TEST_DATA.DB4";
$DIV = "/";
$_FILE = "$DATA_DIR/HUTM_NETWORK_ROUTER.DB"; // DB4 FileName

$db  = dba_open($DB4_DATABASE,"r","db4");
$key = dba_firstkey($db);
$ii = 0;
while($key != NULL)
{
     $LIST[$ii] = explode($DIV,dba_fetch($key, $db));    // fetch array
    $key = dba_nextkey($db);
    $ii++;
}
dba_close($db);
$total = $ii; // total count

# date sort
sort($LIST,SORT_NUMERIC);    // numeric key sort ..

# list display
for($i=0;$i<$total;$i++)
{
    $oData = explode($DIV,$LIST[$i]);    // key + value (sort)

    $key   = trim(chop($oData[0])); # 키번호 
    $name  = trim(chop($oData[1])); # 이름 
    $count = trim(chop($oData[2])); # 수
    $word  = trim(chop($oData[3])); # 설명

    echo "$key / $name / $count / $word <br>\r\n";
}
?>

::result::

1/korea/5000/word 1
2/usa/35000/word 2
10/japan/25000/word 10
21/china/130000/word 21
Adding new notes is disabled. Please see the links in the Found A Problem? section.
To Top