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

woodbri at swoodbridge.com woodbri at swoodbridge.com
Fri Mar 7 18:27:25 PST 2003


Many thanks to those the responded. 

So, here is an update on what I found.

It seems like the first dbf file or two that I tried to read using 
the php dbase extension may have some kind of problem. Using the code 
below I was able to read other dbf files without a problem and use 
dbase_get_record_with_names().

It is not clear why I had problems with the first two files as they 
seem fine when using dbfdump (the C program that came with shapelib) 
and they work fine otherwise with mapserver, and they work fine with 
the Perl Xbase.pm module. This problem is still a small mystery that 
will have to wait.

So back to the original project ...

-Steve W.

On 7 Mar 2003 at 8:07, woodbri at swoodbridge.com wrote:

> 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>";

    $rr = dbase_get_record_with_names($dbh, 1);
    for (reset($rr); $k = key($rr); next($rr)) {
        print "$k = ".$rr[$k]."\n";
    }


> 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.
> 
> _______________________________________________
> Mapserver-users mailing list
> Mapserver-users at lists.gis.umn.edu
> http://lists.gis.umn.edu/mailman/listinfo/mapserver-users
> 





More information about the MapServer-users mailing list