[Mapserver-users] Reading DBF files with PHP dbase extension?

woodbri at swoodbridge.com woodbri at swoodbridge.com
Fri Mar 7 05:07:32 PST 2003


OK, this is getting a little bit off topic, but I am trying to do a 
query then fetch attributes from the DBF using the PHP dbase 
extension. 

I'm using older versions of PHP-4.2.2 it test this on with code like:

<?php
### try to read a dbf file

$dbh = @ dbase_open('/data/mdata/us/us_pop2k.dbf', READ_ONLY) or
    die("Could not open '/data/mdata/nhpn.dbf' for read.");

$num_fields = dbase_numfields ($dbh);
$num_rows   = dbase_numrecords($dbh);

print "<br>num_fields = $num_fields\n";
print "<br>num_rows   = $num_rows\n";

print   "<pre>";
for ($i=1; $i <= 10; $i++) {
    $row = dbase_get_record($dbh, $i);
    printf("%7d: %s\n", $i, join("|", $row));
}
print   "</pre>";

dbase_close($dbh);
?>

It seems to work, but I get varying results with different DBF files. 
And if I try to use dbase_get_record_with_names() the script dies on 
that call without any errors.

I'll try this again on PHP-4.3.1 tonight, but wondering if anyone 
else has tried going this with or without success?

Thanks,
   Steve W.




More information about the MapServer-users mailing list