PHP: Hypertext Preprocessor (original) (raw)

dba_firstkey

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

dba_firstkey — Fetch first key

Description

Return Values

Returns the key on success or [false](reserved.constants.php#constant.false) on failure.

Changelog

Version Description
8.4.0 The dba parameter expects a Dba\Connection instance now; previously, a valid dba resource was expected.

See Also

Found A Problem?

jacky dot jackyhung dot net

23 years ago

for ($key = dba_firstkey($this->handle); <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>k</mi><mi>e</mi><mi>y</mi><mo stretchy="false">!</mo><mo>=</mo><mo>=</mo><mi>f</mi><mi>a</mi><mi>l</mi><mi>s</mi><mi>e</mi><mo separator="true">;</mo></mrow><annotation encoding="application/x-tex">key !== false; </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.03148em;">k</span><span class="mord mathnormal" style="margin-right:0.03588em;">ey</span><span class="mclose">!</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">==</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal">a</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">se</span><span class="mpunct">;</span></span></span></span>key = dba_nextkey($this->handle)) { <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>k</mi><mi>e</mi><mi>y</mi><mi>s</mi><mi>e</mi><mi>t</mi><mo stretchy="false">[</mo><mo stretchy="false">]</mo><mo>=</mo></mrow><annotation encoding="application/x-tex">keyset[] = </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.03148em;">k</span><span class="mord mathnormal">eyse</span><span class="mord mathnormal">t</span><span class="mopen">[</span><span class="mclose">]</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span></span></span></span>key; } // end for

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

k!=false;k != false; k!=false;k = dba_nextkey($handle)) { assoc[assoc[assoc[k] = dba_fetch($k, $handle); } return $assoc; } ?>

`

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("
");
} while ($the_key = dba_nextkey($DBCon));
print ("


Well looks like we're done here :-)");

`