|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2001-06-12 03:25 UTC] sniper@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 21:00:01 2025 UTC |
I am new to php and DBMs, and I have trouble reading from (or writing to) the DBM flat file. Other possibly related bugs: Bug id #9222 and #9283 The writer code: <?PHP $fn = "./DBMData/products"; $dbh = dbmopen($fn,"c") or die ("Couldn't open test DBM"); $item="Screwdriver"; $item_p="12.34"; if (dbmexists ($dbh, $item)) { dbmreplace($dbh, $item, $item_p); } else { dbminsert ($dbh, $item, $item_p); } $item="Tricorder"; $item_p="2.34"; if (dbmexists ($dbh, $item)) { dbmreplace($dbh, $item, $item_p); } else { dbminsert ($dbh, $item, $item_p); } $item="ORAC"; $item_p="98.76"; if (dbmexists ($dbh, $item)) { dbmreplace($dbh, $item, $item_p); } else { dbminsert ($dbh, $item, $item_p); } $item="HAL 2000"; $item_p="99.97"; if (dbmexists ($dbh, $item)) { dbmreplace($dbh, $item, $item_p); } else { dbminsert ($dbh, $item, $item_p); } dbmclose($dbh); ?> The DBM file created: 11 Screwdriver5 12.349 Tricorder4 2.344 ORAC5 98.768 HAL 20005 99.97 The reader code: <?PHP $fn = "./DBMData/products"; $dbh = dbmopen($fn,"c") or die ("Couldn't open test DBM"); $key = dbmfirstkey($dbh); while ($key != "") { $value = dbmfetch($dbh, $key); print "<TR>"; print "<TD ALIGN=\"left\">$key</TD>"; print "<TD ALIGN=\"right\">\$$value</TD>"; print "</TR>\n"; $key = dbmnextkey($dbh, $key); } dbmclose($dbh); ?> The output: crewdriver5 $ Tricorder $2.34 ORAC $98.76 HAL 2000 $9.972 Thanks in advace, Ridley