Page 1 of 1

dbf file

Posted: Mon Jun 19, 2006 7:18 pm
by nikanj
I've got a .dbf file (foxpro, I believe) that I would like to read. The file is part of another application that updates it once in a while, ie: it is not static, it gets changed and must be read every other day or so.

I want to be able to open the file and import it to a mysql database, updating the mysql table on a regular basis.

The problem: I tried the following code

Code: Select all

$id = @dbase_open("contacts.dbf", 0)
   or die ("Could not open dbf file."); 
   
$record = dbase_get_record($id, 955);
But, I get the error (as you might expect) "Could not open dbf file." I've tried using PHP to create and then read a test dbf file and that works fine, so I think there is a problem with the file. The file is in the proper location and is accessible (it's in the same folder as the test dbf file.)

The program DBFview shows me this info about the file:

Code: Select all

C:\www\contacts\contacts.dbf
 File size (bytes): 1793394
 Version: FoxPro with memo, index present
 Number of records: 9640

   N  Field name    Type     Width
 ---------------------------------
   1  ID         Numeric      10
   2  LINKID     Numeric      10
   3  FNAME      Character    24
   4  LNAME      Character    24
   5  COMPANY    Character    48
   6  COMPID     Character     8
   7  OCUPATION  Character    16
   8  POSITION   Character    16
   9  LASTUPDATE Float        19.9
  10  TEXTBLOB   Memo         10
 ---------------------------------
 Total:                      186
I noticed another post on this forum that talked about the wrong version of dbf file and I'm hoping that this is not the case for me. Other than contacting the developer is there anyway to find out? Does anybody have any other suggestions?

BTW: I can't just use something like dbfviewer to produce the sql to insert it into a mysql table, because the file is "live" being changed daily by another application.

BBTW: the contacts.dbf file I'm testing on, is NOT live -- it has been copied to another directory so I can play with it, without damaging the original.

My Setup:
Apache2
PHP5 (with php_dbase.dll)
win xp

I'm thinking, perhaps there might be a way to treat this as a flat text file that I can extract rows from. Not sure, I'll have to play with it.

If I left anything out, ask me..... and thanks in advance.

Re: dbf file

Posted: Mon Jun 19, 2006 7:38 pm
by Christopher
Given the error message you might want to try something like:

Code: Select all

$id = @dbase_open('C:/www/contacts/contacts.dbf', 0)
   or die ("Could not open dbf file."); 
   
$record = dbase_get_record($id, 955);

Re: dbf file

Posted: Mon Jun 19, 2006 8:28 pm
by nikanj
Thanks. I just tried that and still, the same problem.

I tried this, on another file that's right next to contacts.dbf and it works.

Code: Select all

<?php 

$id = @dbase_open('C:/www/contacts/dbfile_test.dbf', 0)
   or die ("Could not open dbf file.");
   
$record = dbase_get_record($id, 1);
?>
Any suggestions on how I might get something in the die that will give me a more descriptive error. Something perhaps equivalent to mysql_error()?

I'm experimenting with ODBC, but not having much luck... since I've only got a .dbf file available. ODBC seems to want a .dbc file.

Posted: Mon Jun 19, 2006 9:33 pm
by Christopher
You might want to get a dbf file viewer and see if the contact file is corrupted or so unsupported version. You might be able to get a text export out of the file at minimum if it's not corrupted.

Posted: Mon Jun 19, 2006 9:49 pm
by Luke
arborint wrote:You might want to get a dbf file viewer and see if the contact file is corrupted or so unsupported version. You might be able to get a text export out of the file at minimum if it's not corrupted.
I was looking for a dbf editor in an earlier thread and found that the reason I could not work with the file is because it uses the dbf extension, but it is was proprietary to MIVAsql (I'm not saying that is the case for you, but here is the thread).

viewtopic.php?t=48841&highlight=dbf

There are a bunch of editors referenced in there.